1
0

user_credentials_controller.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. class UserCredentialsController < ApplicationController
  2. include SortableTable
  3. def index
  4. set_table_sort sorts: %w[credential_name credential_value], default: { credential_name: :asc }
  5. @user_credentials = current_user.user_credentials.reorder(table_sort).page(params[:page])
  6. respond_to do |format|
  7. format.html
  8. format.json {
  9. send_data Utils.pretty_jsonify(@user_credentials.limit(nil).as_json), disposition: 'attachment'
  10. }
  11. end
  12. end
  13. def new
  14. @user_credential = current_user.user_credentials.build
  15. respond_to do |format|
  16. format.html
  17. format.json { render json: @user_credential }
  18. end
  19. end
  20. def edit
  21. @user_credential = current_user.user_credentials.find(params[:id])
  22. end
  23. def create
  24. @user_credential = current_user.user_credentials.build(params[:user_credential])
  25. respond_to do |format|
  26. if @user_credential.save
  27. format.html { redirect_to user_credentials_path, notice: 'Your credential was successfully created.' }
  28. format.json { render json: @user_credential, status: :created, location: @user_credential }
  29. else
  30. format.html { render action: "new" }
  31. format.json { render json: @user_credential.errors, status: :unprocessable_entity }
  32. end
  33. end
  34. end
  35. def update
  36. @user_credential = current_user.user_credentials.find(params[:id])
  37. respond_to do |format|
  38. if @user_credential.update_attributes(params[:user_credential])
  39. format.html { redirect_to user_credentials_path, notice: 'Your credential was successfully updated.' }
  40. format.json { head :no_content }
  41. else
  42. format.html { render action: "edit" }
  43. format.json { render json: @user_credential.errors, status: :unprocessable_entity }
  44. end
  45. end
  46. end
  47. def destroy
  48. @user_credential = current_user.user_credentials.find(params[:id])
  49. @user_credential.destroy
  50. respond_to do |format|
  51. format.html { redirect_to user_credentials_path }
  52. format.json { head :no_content }
  53. end
  54. end
  55. end