So I have this in my application.html.erb file:
<div class="mainMenu">
<%= link_to 'Movies', dvds_path %>
<%= link_to 'Books', books_path %>
<%= link_to 'Albums', cds_path %>
<%= link_to 'Games', games_path %>
</div>
I would like to put a class of “highlight” on the menus if we are on each of the pages, so for example, in the Movies page, if we are in dvds_path then it would be:
<%= link_to 'Movies', dvds_path, :class => 'highlight' %>
But can’t seem to figure it out, none of these methods worked for me:
Any help would be appreciated
You could use:
Creates a link tag of the given name using a URL created by the set of options unless the current request URI is the same as the links, in which case only the name is returned (or the given block is yielded, if one exists). You can give link_to_unless_current a block which will specialize the default behavior (e.g., show a “Start Here” link rather than the link’s text).
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to_unless_current
So you could style your ‘links’ as unselected in your nav bar, and have a ‘selected’ style when the link is not present..