Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountsController < ApplicationController
- before_action :set_account, only: [:show, :update, :destroy]
- # GET /accounts
- def index
- @accounts = Accounts.all
- render json: @accounts
- end
- # GET /accounts/1
- def show
- render json: @account
- end
- # POST /models
- def create
- @account = Account.new(account_params)
- if @account.save
- render json: @account, status: :created, location: @account
- else
- render json: @account.errors, status: :unprocessable_entity
- end
- end
- # PATCH/PUT /account/1
- def update
- if @account.update(account_params)
- render json: @account
- else
- render json: @account.errors, status: :unprocessable_entity
- end
- end
- # DELETE /models/1
- def destroy
- @account.destroy
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_account
- @account = Account.find(params[:id])
- end
- # Only allow a trusted parameter "white list" through.
- def model_params
- params.require(:account).permit(:accounts, :name, :category)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement