Class: Thesis::ThesisController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ControllerHelpers
Defined in:
lib/thesis/controllers/thesis_controller.rb

Instance Method Summary collapse

Methods included from ControllerHelpers

#current_page, included, #root_pages, #thesis_editor

Instance Method Details

#new_pageObject



15
16
17
18
19
20
21
22
# File 'lib/thesis/controllers/thesis_controller.rb', line 15

def new_page      
  page = Page.new
  return head :forbidden unless page_is_editable?(page)

  update_page_attributes page

  head page.save ? :ok : :not_acceptable
end

#page_attributesObject



33
34
35
# File 'lib/thesis/controllers/thesis_controller.rb', line 33

def page_attributes
  [ :name, :title, :description, :parent_id ]
end

#showObject

Raises:

  • (ActionController::RoutingError)


5
6
7
8
9
10
11
12
13
# File 'lib/thesis/controllers/thesis_controller.rb', line 5

def show
  raise ActionController::RoutingError.new('Not Found') unless current_page

  if current_page.template && template_exists?("page_templates/#{current_page.template}")
    render "page_templates/#{current_page.template}"
  else
    raise PageRequiresTemplate.new("Page requires a template but none was specified.")
  end
end

#update_pageObject



24
25
26
27
28
29
30
31
# File 'lib/thesis/controllers/thesis_controller.rb', line 24

def update_page
  page = current_page
  return head :forbidden unless page_is_editable?(page)

  update_page_attributes page
  
  head page.save ? :ok : :not_acceptable
end

#update_page_attributes(page) ⇒ Object



37
38
39
40
# File 'lib/thesis/controllers/thesis_controller.rb', line 37

def update_page_attributes(page)
  page_attributes.each { |a| page.send("#{a}=", params[a]) if params[a] }
  page
end