Re: Conditional Menu in View = How do you create handle this scenario ?

Jason Gilstrap
Tue, 20 Sep 2005 12:44:56 -0000

Have you considered using either link_to_unless or link_to_unless_current?
http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000310

-Jason Gilstrap
 info-Yf9cRGTgqmECWBydzj52wkEOCMrvLtNR@public.gmane.org

Mats Persson wrote:

>
> Hi all,
>
> <NewbieAlert>
>
> I''m just working on this site with a main_nav menu that should
> highlight the active section on each request. This code worked
> perfectly when I had all the sections as methods in [ /app/
> controllers/application.rb ], but not when I began transforming some
> sections [ skills, clients, portfolio ] to their own controllers.
>
> I guess I should use something like [  if @params[:controller] =~ /
> ^<controller_name>/  ] to test for each of the controllers, but that
> seems to unsophisticated for Ruby/Rails, so I''m hoping
there''s a
> smarter way. Is there ?
>
>
>   def main_nav
>     # temporary array of possible menu items
>     menus = %w{ home experience skills clients portfolio contact }
>     nav = String.new
> nav << " \n"
>     menus.each do |menu|
>       if controller.action_name.downcase == menu.downcase
> nav << " <a href=\"#\"
class=\"active\">#{menu.capitalize}
> \n"
>       else
>         if menu.downcase == ''home''
> nav << " <a
href=\"/\">#{menu.capitalize} \n"
>         else
> nav << " <a
href=\"/#{menu.downcase}/\">#
> {menu.capitalize} \n"
>         end
>       end
>     end
> nav << " \n"
>   end
>
> </NewbieAlert>
>
>
> Kind regards,
>
> Mats
>
> ----
> "TextMate, coding with an incredible sense of joy and ease"
> - www.macromates.com -
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails