Simple highlighted HTML-Menus in Rails. No more crazy view logic, no instance variables in controllers - you can be happy with your menu again.
<% happy_menu do %> <% happy_menu_item "Start", dashboard_path, [{:dashboard => [:index]}] %> <% happy_menu_item "Projects", projects_path, [:projects] %> <% happy_menu_item "Log Out", logout_path, nil %> <% end %>
Let’s say you are calling the dashboard controller’s index action.
<ul> <li><a href="your_dashboard_link" class="selected"></a></li> <li><a href="your_projects_link"></a></li> <li><a href="your_log_out_link"></a></li> </ul>
Still to come
HappyMenu provides simple ViewHelpers and performs the selection of a menu item based on the current controller action. It uses the controller_name and action_name to determine the current selection. It expects an array or nil. Each array element can either be a symbol or a hash. Use a symbol if all controller actions should be selected, a hash to set the selection per action.
HappyMenu can either be customized on a global level or via each method call. See HappyMenu::Base for details.
-
Rails version testing (Not tested in Rails 3 yet)
-
Fix indentation for haml templates
Thanks to Henning Peters for the initial idea.
Copyright © 2010 Daniel Schoppmann, released under the MIT license