/ Published in: Rails
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#
# PagesController
#
# This controller works differently than most normal rails controllers. The pages controller here is used
# as a traffic cop for static and semi-static pages in the rails site, with database information collected
# from the necessary classes.
class PagesController < PublicController
layout 'public'
caches_page :show, :index
# Renders the home page for the site
def index
@page = Page.find_by_name("home")
end
# Attempts to render a page directly from the views/pages directory. If no page is found a 404 will be rendered
def show
action_name = params[:path].join('/')
@page = Page.find_by_path("/" + action_name)
# Check to see that the page exists in the database and has a corresponding template file
if @page && page_exist?(action_name)
load_restaurant_page_data if @page.in_dining?
render :action => action_name, :layout => @page.view_layout
else
render :action => "404", :layout => true, :status => 404
end
end
private
# Deterine if the page we're trying to access exists
# <tt>path</tt> The name of the file we're trying to access, like "visit-telluride/index"
def page_exist?(path)
file_path = File.join(RAILS_ROOT, "app", "views", "pages", "#{path}.html.erb")
return true if File.exists?(file_path)
end
# Returns a layout for special case pages. Currently, all views except the app/views/photos/index use the public layout
def find_layout(page_name)
action_name == ""
end
end
Comments
 Subscribe to comments
                    Subscribe to comments
                
                