Posted By

chrisaiv on 07/04/10


Tagged

rails helper


Versions (?)

Rails: Simple nav link helper


 / Published in: Rails
 

In an effort to stay DRY, here's a simple way to organize your main navigation.

  1. #1. Insert this in /rails_app/helpers/application_helper.rb
  2. def nav_link( text, controller, action="index" )
  3. link_to_unless_current text, :controller => controller,
  4. :action => action
  5. end
  6.  
  7. #2. Make a Call from /views/layouts/application_helper.rb
  8. <div id="nav">
  9. <%= nav_link "Home", "site" %>
  10. <%= nav_link "About", "site", "about" %>
  11. <%= nav_link "Help", "site", "help" %>
  12. </div>

Report this snippet  

You need to login to post a comment.