user_credentials_controller.rb 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { render json: @user_credentials }
  9. end
  10. end
  11. def new
  12. @user_credential = current_user.user_credentials.build
  13. respond_to do |format|
  14. format.html
  15. format.json { render json: @user_credential }
  16. end
  17. end
  18. def edit
  19. @user_credential = current_user.user_credentials.find(params[:id])
  20. end
  21. def create
  22. @user_credential = current_user.user_credentials.build(params[:user_credential])
  23. respond_to do |format|
  24. if @user_credential.save
  25. format.html { redirect_to user_credentials_path, notice: 'Your credential was successfully created.' }
  26. format.json { render json: @user_credential, status: :created, location: @user_credential }
  27. else
  28. format.html { render action: "new" }
  29. format.json { render json: @user_credential.errors, status: :unprocessable_entity }
  30. end
  31. end
  32. end
  33. def update
  34. @user_credential = current_user.user_credentials.find(params[:id])
  35. respond_to do |format|
  36. if @user_credential.update_attributes(params[:user_credential])
  37. format.html { redirect_to user_credentials_path, notice: 'Your credential was successfully updated.' }
  38. format.json { head :no_content }
  39. else
  40. format.html { render action: "edit" }
  41. format.json { render json: @user_credential.errors, status: :unprocessable_entity }
  42. end
  43. end
  44. end
  45. def destroy
  46. @user_credential = current_user.user_credentials.find(params[:id])
  47. @user_credential.destroy
  48. respond_to do |format|
  49. format.html { redirect_to user_credentials_path }
  50. format.json { head :no_content }
  51. end
  52. end
  53. end