Class: Admin::PagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/pages_controller.rb', line 21

def create
  @page = Effective::Page.new(page_params)
  @page_title = 'New Page'

  EffectivePages.authorized?(self, :create, @page)

  if @page.save
    if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
      redirect_to effective_regions.edit_path(effective_pages.page_path(@page), :exit => effective_pages.edit_admin_page_path(@page))
    elsif params[:commit] == 'Save and Add New'
      redirect_to effective_pages.new_admin_page_path
    else
      flash[:success] = 'Successfully created page'
      redirect_to effective_pages.edit_admin_page_path(@page)
    end
  else
    flash.now[:danger] = 'Unable to create page'
    render :action => :new
  end
end

#destroyObject



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/admin/pages_controller.rb', line 70

def destroy
  @page = Effective::Page.find(params[:id])

  EffectivePages.authorized?(self, :destroy, @page)

  if @page.destroy
    flash[:success] = 'Successfully deleted page'
  else
    flash[:danger] = 'Unable to delete page'
  end

  redirect_to effective_pages.admin_pages_path
end

#editObject



42
43
44
45
46
47
# File 'app/controllers/admin/pages_controller.rb', line 42

def edit
  @page = Effective::Page.find(params[:id])
  @page_title = 'Edit Page'

  EffectivePages.authorized?(self, :edit, @page)
end

#indexObject



7
8
9
10
11
12
# File 'app/controllers/admin/pages_controller.rb', line 7

def index
  @page_title = 'Pages'
  EffectivePages.authorized?(self, :index, Effective::Page)

  @datatable = Effective::Datatables::Pages.new() if defined?(EffectiveDatatables)
end

#newObject



14
15
16
17
18
19
# File 'app/controllers/admin/pages_controller.rb', line 14

def new
  @page = Effective::Page.new()
  @page_title = 'New Page'

  EffectivePages.authorized?(self, :new, @page)
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/admin/pages_controller.rb', line 49

def update
  @page = Effective::Page.find(params[:id])
  @page_title = 'Edit Page'

  EffectivePages.authorized?(self, :update, @page)

  if @page.update_attributes(page_params)
    if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
      redirect_to effective_regions.edit_path(effective_pages.page_path(@page), :exit => effective_pages.edit_admin_page_path(@page))
    elsif params[:commit] == 'Save and Add New'
      redirect_to effective_pages.new_admin_page_path
    else
      flash[:success] = 'Successfully updated page'
      redirect_to effective_pages.edit_admin_page_path(@page)
    end
  else
    flash.now[:danger] = 'Unable to update page'
    render :action => :edit
  end
end