Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Created January 14, 2013 23:57
Show Gist options
  • Save telagraphic/4534695 to your computer and use it in GitHub Desktop.
Save telagraphic/4534695 to your computer and use it in GitHub Desktop.
class CreditsController < ApplicationController
def new
@current_account = signed_in_user.accounts.find(params[:account_id])
@new_credit = Credit.new
@new_credit.account_id = @current_account.id
end
def create
@current_account = signed_in_user.accounts.find(params[:account_id])
@new_credit = @current_account.credits.build(params[:credit])
if @new_credit.save
@current_account.update_attributes(balance: @current_account.balance += @new_credit.amount)
redirect_to account_path(@current_account)
else
render "new"
end
end
def credit_report
@current_account = signed_in_user.accounts.find(params[:account_id])
@total_credits = @current_account.credits.sum("amount")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment