Created
March 14, 2016 21:07
-
-
Save quadriq/f59e65dd34495e08eaee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaymethodsController < ApplicationController | |
before_action :set_paymethod, only: [:show, :update, :destroy] | |
# GET /paymethods | |
def index | |
@paymethods = Paymethod.all | |
render json: @paymethods | |
end | |
# GET /paymethods/1 | |
def show | |
render json: @paymethod | |
end | |
# POST /paymethods | |
def create | |
@paymethod = Paymethod.new(paymethod_params) | |
if @paymethod.save | |
render json: @paymethod, status: :created, location: @paymethod | |
else | |
render json: @paymethod.errors, status: :unprocessable_entity | |
end | |
end | |
# PATCH/PUT /paymethods/1 | |
def update | |
if @paymethod.update(paymethod_params) | |
render json: @paymethod | |
else | |
render json: @paymethod.errors, status: :unprocessable_entity | |
end | |
end | |
# DELETE /paymethods/1 | |
def destroy | |
@paymethod.destroy | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_paymethod | |
@paymethod = Paymethod.find(params[:id]) | |
end | |
# Only allow a trusted parameter "white list" through. | |
def paymethod_params | |
params.require(:paymethod).permit(:title, :amount) | |
end | |
end | |
class TransactionsController < ApplicationController | |
before_action :set_transaction, only: [:show, :update, :destroy] | |
# GET /transactions | |
def index | |
@transactions = Transaction.all | |
render json: @transactions | |
end | |
# GET /transactions/1 | |
def show | |
render json: @transaction | |
end | |
# POST /transactions | |
def create | |
@transaction = Transaction.new(transaction_params) | |
if @transaction.save | |
render json: @transaction, status: :created, location: @transaction | |
else | |
render json: @transaction.errors, status: :unprocessable_entity | |
end | |
end | |
# PATCH/PUT /transactions/1 | |
def update | |
if @transaction.update(transaction_params) | |
render json: @transaction | |
else | |
render json: @transaction.errors, status: :unprocessable_entity | |
end | |
end | |
# DELETE /transactions/1 | |
def destroy | |
@transaction.destroy | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_transaction | |
@transaction = Transaction.find(params[:id]) | |
end | |
# Only allow a trusted parameter "white list" through. | |
def transaction_params | |
params.require(:transaction).permit(:balance, :ammount, :user_id, :paymethod_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment