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
41
42
43
# File 'app/controllers/admin/pages_controller.rb', line 21

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

  authorize_effective_pages!

  if @page.save
    if params[:commit] == 'Save and Edit Content'
      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'
      flash[:success] = 'Successfully created page'
      redirect_to effective_pages.new_admin_page_path
    elsif params[:commit] == 'Save and View'
      redirect_to effective_pages.page_path(@page)
    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



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/admin/pages_controller.rb', line 87

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

  authorize_effective_pages!

  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



45
46
47
48
49
50
# File 'app/controllers/admin/pages_controller.rb', line 45

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

  authorize_effective_pages!
end

#indexObject



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

def index
  @datatable = EffectivePagesDatatable.new(self)
  @page_title = 'Pages'

  authorize_effective_pages!
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'

  authorize_effective_pages!
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/admin/pages_controller.rb', line 52

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

  authorize_effective_pages!

  if @page.update_attributes(page_params)
    if params[:commit] == 'Save and Edit Content'
      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'
      flash[:success] = 'Successfully updated page'
      redirect_to effective_pages.new_admin_page_path
    elsif params[:commit] == 'Save and View'
      redirect_to effective_pages.page_path(@page)
    elsif params[:commit] == 'Duplicate'
      begin
        page = @page.duplicate!
        flash[:success] = 'Successfully saved and duplicated page.'
        flash[:info] = "You are now editting the duplicated page. This new page has been created as a Draft."
      rescue => e
        flash.delete(:success)
        flash[:danger] = "Unable to duplicate page: #{e.message}"
      end

      redirect_to effective_pages.edit_admin_page_path(page || @page)
    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