Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class AccountsController < ApplicationController
  2. before_action :set_account, only: [:show, :update, :destroy]
  3.  
  4. # GET /accounts
  5. def index
  6. @accounts = Accounts.all
  7.  
  8. render json: @accounts
  9. end
  10.  
  11. # GET /accounts/1
  12. def show
  13. render json: @account
  14. end
  15.  
  16. # POST /models
  17. def create
  18. @account = Account.new(account_params)
  19.  
  20. if @account.save
  21. render json: @account, status: :created, location: @account
  22. else
  23. render json: @account.errors, status: :unprocessable_entity
  24. end
  25. end
  26.  
  27. # PATCH/PUT /account/1
  28. def update
  29. if @account.update(account_params)
  30. render json: @account
  31. else
  32. render json: @account.errors, status: :unprocessable_entity
  33. end
  34. end
  35.  
  36. # DELETE /models/1
  37. def destroy
  38. @account.destroy
  39. end
  40.  
  41. private
  42. # Use callbacks to share common setup or constraints between actions.
  43. def set_account
  44. @account = Account.find(params[:id])
  45. end
  46.  
  47. # Only allow a trusted parameter "white list" through.
  48. def model_params
  49. params.require(:account).permit(:accounts, :name, :category)
  50. end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement