Class: Admin::AccountsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/pages_cms/admin/accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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()
  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.full_messages.to_sentence}"
    redirect_to admin_accounts_path
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 56

def destroy
   = Account.find(params[:id])
  if session[:current_account] == .id
    session[:current_account] = nil
  end
  .destroy
  flash[:success] = 'Account destroyed'
  redirect_to admin_accounts_path
end

#editObject



29
30
31
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 29

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

#indexObject



7
8
9
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 7

def index
  @accounts = Account.all
end

#newObject



11
12
13
# File 'app/controllers/pages_cms/admin/accounts_controller.rb', line 11

def new
  @account = Account.new
end

#siteObject



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]
     = PagesCms::Account.find(params[:account])
    flash[:success] = "Site changed to #{.site_name}"
    redirect_to admin_accounts_path
  else
    flash[:danger] = 'Site does not exist!'
    redirect_to admin_accounts_path
  end
end

#updateObject



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()
    flash[:success] = 'Account updated'
    redirect_to admin_accounts_path
  else
    flash[:danger] = "Failed to update: #{@account.errors.full_messages.to_sentence}"
    redirect_to admin_accounts_path
  end
end