Module: TinyCore::Controllers::Accounts

Defined in:
lib/tiny_core/controllers/accounts.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



56
57
58
59
# File 'lib/tiny_core/controllers/accounts.rb', line 56

def self.included(receiver)
  receiver.before_filter :login_required
  receiver.before_filter :can_see_account_details!
end

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tiny_core/controllers/accounts.rb', line 22

def create
  @account = Account.new(params[:account])
  if @account.save
    current_user.accounts << @account
    current_user.(@account, 'admin')
    current_user. @account
    flash[:notice] = I18n.t('flash.notice.created_account', :account => @account.name)
    redirect_to root_path
  else
    render :action => 'new'
  end
end

#editObject



17
18
19
20
# File 'lib/tiny_core/controllers/accounts.rb', line 17

def edit
  @account = Account.find(params[:id])
  can_edit_account!(@account)
end

#indexObject



4
5
6
# File 'lib/tiny_core/controllers/accounts.rb', line 4

def index
  @accounts = current_user.accounts.ordered_by_name
end

#newObject



8
9
10
# File 'lib/tiny_core/controllers/accounts.rb', line 8

def new
  @account = Account.new
end

#showObject



12
13
14
15
# File 'lib/tiny_core/controllers/accounts.rb', line 12

def show
  @account = Account.find(params[:id])
  can_see_account!(@account)
end

#switchObject



47
48
49
50
51
52
53
54
# File 'lib/tiny_core/controllers/accounts.rb', line 47

def switch
  @account = Account.find(params[:id])
  can_switch_to_account!(@account) do
    current_user.(@account)
    flash[:notice] = I18n.t('flash.notice.switched_account', :account => @account.name)
    redirect_to root_path
  end
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tiny_core/controllers/accounts.rb', line 35

def update
  @account = Account.find(params[:id])
  can_edit_account!(@account) do
    if @account.update_attributes(params[:account])
      flash[:notice] = I18n.t('flash.notice.updated_account', :account => @account.name)
      redirect_to (@account)
    else
      render :action => 'edit'
    end
  end
end