Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2009 23:55
Show Gist options
  • Save anonymous/264456 to your computer and use it in GitHub Desktop.
Save anonymous/264456 to your computer and use it in GitHub Desktop.
def get_pages_for_tabs
begin
if logged_in? && User.find(current_user).admin?
@tabs = Page.private_pages
else
@tabs = Page.main_pages
end
rescue
logger.error("Rescue Encountered on Method (get_pages_for_tabs) in application_controller.rb" )
@tabs = Page.main_pages
end
end
class Page < ActiveRecord::Base
# our body uses textiled a markup language
acts_as_textiled :body
# here we're specifying the relationship between parent pages and subpages so they belong to one another
has_many :subpages, :class_name => 'Page', :foreign_key => 'parent_id', :order => 'position'
belongs_to :parent, :class_name => 'Page', :foreign_key => 'parent_id'
named_scope :main_pages, :conditions => ['pages.parent_id IS NULL and admin !=?', true], :order => 'pages.position', :include => :subpages
named_scope :private_pages, :conditions => 'pages.parent_id IS NULL', :order => 'pages.position', :include => :subpages
end
# Defines the menu for the application.html.erb (main page)
def menu
html = '<ul id="menunav">'
@tabs.each do |page|
html += '<li style="width: 90px;">'
if page.redirect?
html += link_to(page.navlabel, {:action => page.action_name, :controller => page.controller_name, :name => page.name})
else
html += link_to(page.navlabel, view_page_path(page.name))
end
unless page.subpages.empty?
html += '<ul>'
page.subpages.each do |subpage|
if subpage.redirect?
html += '<li>' + link_to(subpage.navlabel, {:action => subpage.action_name, :controller => subpage.controller_name, :name => subpage.name}) + '</li>'
else
html += '<li>' + link_to(subpage.navlabel, view_page_path(subpage.name)) + '</li>'
end
end
html += '</ul>'
end
html += '</li>'
end
if logged_in?
html += '<li style="width: 90px;">' + link_to("Log Out", logout_path) + '</li>'
else
html += '<li style="width: 90px;">' + link_to("Log In", login_path) + '</li>'
html += '<li style="width: 90px;">' + link_to("Register", signup_path) + '</li>'
end
html += '</ul>'
return html
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment