Class: CmsAdmin::PagesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/cms_admin/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
# File 'app/controllers/cms_admin/pages_controller.rb', line 23

def create
  @cms_page.save!
  flash[:notice] = 'Page saved'
  redirect_to :action => :index
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to create page'
  render :action => :new
end

#destroyObject



41
42
43
44
45
# File 'app/controllers/cms_admin/pages_controller.rb', line 41

def destroy
  @cms_page.destroy
  flash[:notice] = 'Page deleted'
  redirect_to :action => :index
end

#editObject



19
20
21
# File 'app/controllers/cms_admin/pages_controller.rb', line 19

def edit
  render
end

#form_blocksObject



47
48
49
50
# File 'app/controllers/cms_admin/pages_controller.rb', line 47

def form_blocks
  @cms_page = @cms_site.cms_pages.find_by_id(params[:id]) || CmsPage.new
  @cms_page.cms_layout = @cms_site.cms_layouts.find_by_id(params[:layout_id])
end

#indexObject



10
11
12
13
# File 'app/controllers/cms_admin/pages_controller.rb', line 10

def index
  return redirect_to :action => :new if @cms_site.cms_pages.count == 0
  @cms_pages = [@cms_site.cms_pages.root].compact
end

#newObject



15
16
17
# File 'app/controllers/cms_admin/pages_controller.rb', line 15

def new
  render
end

#reorderObject



61
62
63
64
65
66
67
68
# File 'app/controllers/cms_admin/pages_controller.rb', line 61

def reorder
  (params[:cms_page] || []).each_with_index do |id, index|
    if (cms_page = CmsPage.find_by_id(id))
      cms_page.update_attribute(:position, index)
    end
  end
  render :nothing => true
end

#toggle_branchObject



52
53
54
55
56
57
58
59
# File 'app/controllers/cms_admin/pages_controller.rb', line 52

def toggle_branch
  @cms_page = @cms_site.cms_pages.find(params[:id])
  s   = (session[:cms_page_tree] ||= [])
  id  = @cms_page.id.to_s
  s.member?(id) ? s.delete(id) : s << id
rescue ActiveRecord::RecordNotFound
  # do nothing
end

#updateObject



32
33
34
35
36
37
38
39
# File 'app/controllers/cms_admin/pages_controller.rb', line 32

def update
  @cms_page.save!
  flash[:notice] = 'Page updated'
  redirect_to :action => :index
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = 'Failed to update page'
  render :action => :index
end