Highlight Section Navigation


/ Published in: Rails
Save to your folder(s)

note to self


Copy this code and paste it in your HTML
  1. #put in application_helper.rb :
  2.  
  3. def section_link(name,options)
  4. if options[:action] == @current_action and options[:controller] == @current_controller
  5. link_to(name, options, :class => 'on')
  6. else
  7. link_to(name,options)
  8. end
  9. end
  10.  
  11. #initialize vars in controller
  12. before_filter :instantiate_controller_and_action_names
  13.  
  14. def instantiate_controller_and_action_names
  15. @current_action = action_name
  16. @current_controller = controller_name
  17. end
  18.  
  19. #usage in view:
  20. <%=section_link('Home',:controller => 'articles', :action => 'index')%>

URL: http://snippets.dzone.com/posts/show/2016

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.