Class: Lookbook::PagesController

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.controller_pathObject



7
8
9
# File 'app/controllers/lookbook/pages_controller.rb', line 7

def self.controller_path
  "lookbook/pages"
end

Instance Method Details

#indexObject



11
12
13
14
15
16
17
18
# File 'app/controllers/lookbook/pages_controller.rb', line 11

def index
  landing = Lookbook.pages.find(&:landing) || Lookbook.pages.first
  if landing.present?
    redirect_to lookbook_page_path landing.lookup_path
  else
    show_404
  end
end

#showObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/lookbook/pages_controller.rb', line 20

def show
  @page = @pages.find_by_path(params[:path])
  if @page
    @next_page = @pages.find_next(@page)
    @previous_page = @pages.find_previous(@page)
    if @page.errors.any?
      render_in_layout "lookbook/error",
        layout: "lookbook/page",
        error: @page.errors.first
    else
      begin
        @page_content = page_controller.render_page(@page)
        @title = @page.title
      rescue => exception
        render_in_layout "lookbook/error",
          layout: "lookbook/page",
          error: Lookbook::Error.new(exception, file_path: @page.full_path, source_code: @page.content)
      end
    end
  else
    show_404
  end
end