Class: Cms::PagesController

Inherits:
BaseController show all
Includes:
PublishWorkflow
Defined in:
app/controllers/cms/pages_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

allow_guests_to

Methods inherited from ApplicationController

#no_browser_caching

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/cms/pages_controller.rb', line 34

def create
  @page = Page.new(page_params)
  @page.section = @section
  if @page.save
    flash[:notice] = "Page was '#{@page.name}' created."
    redirect_to @page
  else
    render :action => "new"
  end
end

#destroyObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/cms/pages_controller.rb', line 57

def destroy
  respond_to do |format|
    if @page.destroy
      message = "Page '#{@page.name}' was deleted."
      format.html { flash[:notice] = message; redirect_to(sitemap_url) }
      format.json { render :json => {:success => true, :message => message} }
    else
      message = "Page '#{@page.name}' could not be deleted"
      format.html { flash[:error] = message; redirect_to(sitemap_url) }
      format.json { render :json => {:success => false, :message => message} }
    end
  end
end

#newObject



22
23
24
25
26
27
28
# File 'app/controllers/cms/pages_controller.rb', line 22

def new
  @page = Page.new(:section => @section, :cacheable => true)
  if @section.child_nodes.count < 1
    @page.name = "Overview"
    @page.path = @section.path
  end
end

#resourceObject



14
15
16
# File 'app/controllers/cms/pages_controller.rb', line 14

def resource
  @page
end

#resource_paramObject



18
19
20
# File 'app/controllers/cms/pages_controller.rb', line 18

def resource_param
  :page
end

#revert_toObject



99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/cms/pages_controller.rb', line 99

def revert_to
  if @page.revert_to(params[:version])
    flash[:notice] = "Page '#{@page.name}' was reverted to version #{params[:version]}"
  end

  respond_to do |format|
    format.html { redirect_to @page.path }
    format.js { render :template => 'cms/shared/show_notice' }
  end
end

#showObject



30
31
32
# File 'app/controllers/cms/pages_controller.rb', line 30

def show
  redirect_to Page.find(params[:id]).path
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/cms/pages_controller.rb', line 45

def update
  if @page.update(page_params)
    flash[:notice] = "Page was '#{@page.name}' updated."
    redirect_to @page
  else
    render :action => "edit"
  end
rescue ActiveRecord::StaleObjectError => e
  @other_version = @page.class.find(@page.id)
  render :action => "edit"
end

#versionObject



90
91
92
93
94
95
96
97
# File 'app/controllers/cms/pages_controller.rb', line 90

def version
  @page = @page.as_of_version(params[:version])
  @show_toolbar = true
  @show_page_toolbar = true
  @_connectors = @page.current_connectors
  @_connectables = @page.contents
  render :layout => @page.layout, :template => 'cms/content/show'
end