Class: Admin::AccountsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::AccountsController
- Defined in:
- app/controllers/pages_cms/admin/accounts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #site ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 15 def create @account = Account.new(account_params) if @account.save @account.pages.create!(title: 'Home') Rails.application.reload_routes! session[:current_account] = @account.id flash[:success] = 'Account created' redirect_to admin_accounts_path else flash[:danger] = "Failed to create: #{@account.errors..to_sentence}" redirect_to admin_accounts_path end end |
#destroy ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 56 def destroy account = Account.find(params[:id]) if session[:current_account] == account.id session[:current_account] = nil end account.destroy flash[:success] = 'Account destroyed' redirect_to admin_accounts_path end |
#edit ⇒ Object
29 30 31 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 29 def edit @account = Account.find(params[:id]) end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 7 def index @accounts = Account.all end |
#new ⇒ Object
11 12 13 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 11 def new @account = Account.new end |
#site ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 44 def site if Account.exists?(params[:account]) session[:current_account] = params[:account] current_account = PagesCms::Account.find(params[:account]) flash[:success] = "Site changed to #{current_account.site_name}" redirect_to admin_accounts_path else flash[:danger] = 'Site does not exist!' redirect_to admin_accounts_path end end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 33 def update @account = Account.find(params[:id]) if @account.update(account_params) flash[:success] = 'Account updated' redirect_to admin_accounts_path else flash[:danger] = "Failed to update: #{@account.errors..to_sentence}" redirect_to admin_accounts_path end end |