Module: TinyCore::Controllers::Accounts
- Defined in:
- lib/tiny_core/controllers/accounts.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #switch ⇒ Object
- #update ⇒ Object
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
#create ⇒ Object
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.set_role_for_account(@account, 'admin') current_user.switch_to_account @account flash[:notice] = I18n.t('flash.notice.created_account', :account => @account.name) redirect_to root_path else render :action => 'new' end end |
#edit ⇒ Object
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 |
#index ⇒ Object
4 5 6 |
# File 'lib/tiny_core/controllers/accounts.rb', line 4 def index @accounts = current_user.accounts.ordered_by_name end |
#new ⇒ Object
8 9 10 |
# File 'lib/tiny_core/controllers/accounts.rb', line 8 def new @account = Account.new end |
#show ⇒ Object
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 |
#switch ⇒ Object
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.switch_to_account(@account) flash[:notice] = I18n.t('flash.notice.switched_account', :account => @account.name) redirect_to root_path end end |
#update ⇒ Object
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_path(@account) else render :action => 'edit' end end end |