forked from jamis/bucketwise
-
Notifications
You must be signed in to change notification settings - Fork 1
/
statements_controller.rb
54 lines (42 loc) · 1.28 KB
/
statements_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class StatementsController < ApplicationController
before_filter :find_account, :only => %w(index new create)
before_filter :find_statement, :only => %w(show edit update destroy)
def index
@statements = account.statements.balanced
end
def new
@statement = account.statements.build(:ending_balance => account.balance,
:occurred_on => Date.today)
end
def create
@statement = account.statements.create(params[:statement])
redirect_to(edit_statement_url(@statement))
end
def show
end
def edit
@uncleared = account.account_items.uncleared(:with => statement, :include => :event)
end
def update
statement.update_attributes(params[:statement])
redirect_to(account)
end
def destroy
statement.destroy
redirect_to(account)
end
protected
attr_reader :uncleared, :statements
helper_method :uncleared, :statements
attr_reader :account, :statement
helper_method :account, :statement
def find_account
@account = Account.find(params[:account_id])
@subscription = user.subscriptions.find(@account.subscription_id)
end
def find_statement
@statement = Statement.find(params[:id])
@account = @statement.account
@subscription = user.subscriptions.find(@account.subscription_id)
end
end