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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Smith wrote:> 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. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 == view = <ul> <li class="<%= ''current'' if @active_menu_item == ''products'' %>"> ... </li> </ul> 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. On Mar 25, 12:37 pm, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I wonder if link_to_unless_current might work elegantly for you: http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000915 You could use CSS to make the plain text in your list correspond to your current "current" style. -Kyle On Mar 24, 7:07 pm, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > == view => <ul> > <li class="<%= ''current'' if @active_menu_item == ''products'' > %>"> ... </li> > </ul> > > 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. > > On Mar 25, 12:37 pm, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > 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? > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey that''s cool! You also just made me realise that link_to_unless would work quite nicely in different situations as well! :-) On Wed, Mar 26, 2008 at 5:33 AM, Kyle <kyle.rabe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I wonder if link_to_unless_current might work elegantly for you: > > http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000915 > > You could use CSS to make the plain text in your list correspond to > your current "current" style. > > -Kyle > > > > On Mar 24, 7:07 pm, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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 > > > > == view => > <ul> > > <li class="<%= ''current'' if @active_menu_item == ''products'' > > %>"> ... </li> > > </ul> > > > > 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. > > > > On Mar 25, 12:37 pm, John Smith <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > > 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? > > > -- > > > Posted viahttp://www.ruby-forum.com/. > > >-- Jonathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---