hello, I would like to know how could it be possible to set a css class as parameter and a default one. For instance class="active" will be located on the first, second lines, depending on the action. application.html.erb: <li class="active"><a href="#">Tasks</a></li> <li><a href="#">Categories</a></li> <li><a href="#">Calendar</a></li> <li><a href="#">Eisenhower matrix</a></li> Any help would be highly appreciated. bye --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> For instance class="active" will be located on the first, second > lines, depending on the action. > > application.html.erb: > > <li class="active">things.each_with_index do |thing, index| <li <%= ''class="active"'' if index == 2 and params[:action] == ''foo'' %> >Tasks</li> That''s just the sketch of the behaviors - but you must clean it up. The 2 and the ''foo'' should appear in a table, preferably inside the thing model. Controllers should have the minimum possible logical statements, and View should have less. <li class="<%= thing.get_class(index, params[:action]) %>" >Tasks</li> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for helping. Does it mean that I need to create a get_class function in each model (tasks, categories, calendar ...)? Thanks for your help. On 14 juin, 19:22, "Phlip" <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > For instance class="active" will be located on the first, second > > lines, depending on the action. > > > application.html.erb: > > > <li class="active"> > > things.each_with_index do |thing, index| > > <li <%= ''class="active"'' if index == 2 and params[:action] == ''foo'' %> > >Tasks</li> > > That''s just the sketch of the behaviors - but you must clean it up. The 2 > and the ''foo'' should appear in a table, preferably inside the thing model. > Controllers should have the minimum possible logical statements, and View > should have less. > > <li class="<%= thing.get_class(index, params[:action]) %>" >Tasks</li>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could use a method call from a helper. For your example: in the application.html.erb <li class="<%=get_class ''Tasks'' %>"><a href="#">Tasks</a></li> <li class="<%=get_class ''Categories'' %>"><a href="#">Categories</a></ li> <li class="<%=get_class ''Calendar'' %>"><a href="#">Calendar</a></li> <li class="<%=get_class ''Eisenhower matrix'' %>"><a href="#">Eisenhower matrix</a></li> then in the application_helper.rb def get_class(active_action) "active" if @active_action == active_action end then in your actions set the @active_action variable for your default, you could set the @active_action in the application.rb controller, then it will be overwritten if some action specifically overrides the variable --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If you are trying to highlight the active tab a good way of doing it is by giving all the tabs an id as well as a body id for each of the pages that the tabs exist on. Once you do this you have control of the active tab style. ex. <body id="tasks"> <ul id="tabs"> <li id="task_tab">...</li> <li id="categories_tab">...</li> ... # css # the active tab body#tasks li#task_tab, body#categories li#category_tab ... { ... } # the inactive tabs ul#tabs { ... } -- 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 -~----------~----~----~----~------~----~------~--~---