Report abuse


			
## by Ryan Heath: http://rpheath.com
##
## This is a nice and easy way to dynamically build a tabbed menu for certain
## actions within a controller. By using conventions, you can guarantee that 
## the named routes will be unique based on the controller/action pair
## 
## The controller name will be appended onto the links passed into the helper,
## which will also generate the named route for that action as well
##
## The convention:
##   routes:  (name of the action)_(controller_name)
##
## Example will use three actions in public_controller.rb

# views/public/[whatever].rhtml
# <%= navigation ['login','register','about'] -%>

# helpers/application_helper.rb
def navigation(links)
  returning html = "
    " do links.each do |link| html << "
  • #{build_link_for(link)}
  • " end html << "
" end end # helpers/application_helper.rb def css_for(link) controller.action_name.downcase == link.downcase ? 'current' : 'plain' end # helpers/application_helper.rb def build_link_for(link) link_to link.capitalize, send("#{link.downcase}_#{controller.controller_name.downcase}_path") end # config/routes.rb map.with_options :controller => 'public' do |path| path.login_public '/login', :action => 'login' path.register_public '/register', :action => 'register' path.about_public '/about', :action => 'about' end