Created
January 14, 2013 23:57
-
-
Save telagraphic/4534695 to your computer and use it in GitHub Desktop.
This file contains 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 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