Class: SimpleCms::PagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
# File 'app/controllers/simple_cms/pages_controller.rb', line 5

def create
  head '401' and return unless admin_signed_in?
  @full_page = SimpleCms::FullPage.find_or_create_by_name(params[:name], :title => params[:name].gsub('/', ' ').titleize, :content => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
  redirect_to main_app.page_path(@full_page.name)
end

#deleteObject



31
32
33
34
35
36
# File 'app/controllers/simple_cms/pages_controller.rb', line 31

def delete
  head '401' and return unless admin_signed_in?
  @page = SimpleCms::Page.find(params[:id])
  @page.destroy
  redirect_to simple_cms_admin_path, notice: "Page deleted"
end

#showObject

Raises:

  • (ActionController::RoutingError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/simple_cms/pages_controller.rb', line 11

def show
  raise ActionController::RoutingError.new(error_msg) unless params[:format].blank? || params[:format] == "html"

  @full_page = SimpleCms::FullPage.find_by_name(params[:name])
  if @full_page.nil?
    if admin_signed_in?
      render 'simple_cms/pages/new'
    else
      raise ActionController::RoutingError.new(error_msg)
    end
  end
end

#updateObject



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

def update
  @page = SimpleCms::Page.find(params[:id])
  head '401' and return unless admin_signed_in? || @page.editable?(current_user)
  @page.update_attributes(params[:page])
  head '200'
end