Module: TinyCore::Controllers::UserAccounts

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



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

def self.included(receiver)
  receiver.before_filter :find_account
end

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tiny_core/controllers/user_accounts.rb', line 18

def create
  can_add_user_to_account!(@account) do
    @user_account = @account.user_accounts.build(params[:user_account])
    if @user_account.save
      flash[:notice] = I18n.t('flash.notice.created_user_account')
      redirect_to (@account)
    else
      render :action => 'new'
    end
  end
end

#destroyObject



42
43
44
45
46
47
48
49
# File 'lib/tiny_core/controllers/user_accounts.rb', line 42

def destroy
  @user_account = @account.user_accounts.find(params[:id])
  can_remove_user_from_account!(@user_account.user, @account) do
    @user_account.destroy
    flash[:notice] = I18n.t('flash.notice.removed_user_account')
    redirect_to (@account)
  end
end

#indexObject



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

def index
  redirect_to (@account)
end

#newObject



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

def new
  can_add_user_to_account!(@account) do
    @user_account = @account.user_accounts.build
  end
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tiny_core/controllers/user_accounts.rb', line 30

def update
  @user_account = UserAccount.find(params[:id])
  can_assign_role_for_user_and_account!(@user_account.user, @account) do
    if @user_account.update_attributes(params[:user_account])
      flash[:notice] = I18n.t('flash.notice.assign_roles')
    else
      flash[:error] = I18n.t('flash.error.assign_roles')
    end
    redirect_to (@account)
  end
end