I have this code in application.html.erb:
<ul class="glossymenu">
<li class ="current"> <%= link_to _('<b>Repair tickets</b>'),
repair_tickets_path%> </li>
<li><%= link_to _('<b>Incidences</b>'), incidences_path%></li>
<li><%= link_to _('<b>Tickets</b>'), tickets_path%></li>
<li><%= link_to _('<b>Clients</b>'), clients_path%></li>
<li><%= link_to _('<b>Products</b>'), products_path %></li>
</ul>
I want that once I have pressed the Incidences link, the li class
becomes <li class =" current">, meanwhile the li class from Repair
tickets becomes <li>. How can I do that?
I have this code in application.html.erb:
<ul class="glossymenu">
<li class ="current"> <%= link_to _('<b>Repair tickets</b>'),
repair_tickets_path%> </li>
<li><%= link_to _('<b>Incidences</b>'), incidences_path%></li>
<li><%= link_to _('<b>Tickets</b>'), tickets_path%></li>
<li><%= link_to _('<b>Clients</b>'), clients_path%></li>
<li><%= link_to _('<b>Products</b>'), products_path %></li>
</ul>
I want that once I have pressed the Incidences link, the li class
becomes <li class =" current">, meanwhile the li class from Repair
tickets becomes <li>. How can I do that?
I'm going to assume you're using Prototype. If not, I'm sure there is a
JQuery equivalent.
Look up addClassName and removeClassName. You will need to create an
onclick event handler. I'd probably give each LI an id and pass that
into a function, but you could do it in the inline onclick handler if
you really wanted to. It certainly wouldn't be DRY.
The way i've always done this is to set a global variable to some
value, and check for this in the view. It is messy though so i'm
interested to hear any better solutions.
example of what i do:
== controller ==
def some_action
@active_menu_item = "products"
end
You could clean this up my making a helper method for the view, and a
before filter in your products controller that sets the active menu
item, but this is the only solution I've managed to find.