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



5
6
7
# File 'app/controllers/lookbook/pages_controller.rb', line 5

def self.controller_path
  "lookbook/pages"
end

Instance Method Details

#indexObject



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

def index
  landing = Lookbook.pages.find(&:landing) || Lookbook.pages.first
  if landing.present?
    redirect_to lookbook_page_path landing.lookup_path
  else
    @title = "Not found"
    render "not_found"
  end
end

#showObject



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

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