Class: PagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @page = Page.new(params[:page])
  @page.save!
  flash[:notice] = 'Page was successfully created.'
  redirect_to(@page)
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = "There was a problem creating the page"
  render :action => "new"
end

#destroyObject



80
81
82
83
# File 'app/controllers/pages_controller.rb', line 80

def destroy
  @page.destroy
  redirect_to(pages_path)
end

#editObject



57
58
59
# File 'app/controllers/pages_controller.rb', line 57

def edit
  @page_title = "Edit CCLS Page #{@page.title(session[:locale])}"
end

#indexObject



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

def index
  @page_title = "CCLS Pages"
  params[:parent_id] = nil if params[:parent_id].blank?
  @pages = Page.all(:conditions => { :parent_id => params[:parent_id] })
end

#newObject



52
53
54
55
# File 'app/controllers/pages_controller.rb', line 52

def new
  @page_title = "Create New CCLS Page"
  @page = Page.new(:parent_id => params[:parent_id])
end

#orderObject



28
29
30
31
32
33
34
35
# File 'app/controllers/pages_controller.rb', line 28

def order
#   params[:pages].reverse.each { |id| Page.find(id).move_to_top }
# this doesn't even check for parents or anything
# making it faster, but potentially error prone.
  params[:pages].each_with_index { |id,index| 
    Page.find(id).update_attribute(:position, index+1 ) }
  redirect_to pages_path(:parent_id=>params[:parent_id])
end

#showObject



43
44
# File 'app/controllers/pages_controller.rb', line 43

def show
end

#translateObject



37
38
39
40
41
# File 'app/controllers/pages_controller.rb', line 37

def translate
  respond_to do |format|
    format.js {}
  end
end

#updateObject



71
72
73
74
75
76
77
78
# File 'app/controllers/pages_controller.rb', line 71

def update
  @page.update_attributes!(params[:page])
  flash[:notice] = 'Page was successfully updated.'
  redirect_to(@page)
rescue ActiveRecord::RecordInvalid
  flash.now[:error] = "There was a problem updating the page."
  render :action => "edit"
end