Forum: Ruby on Rails How to select a style based on the controller?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Patrick D. (Guest)
on 2008-12-11 20:33
(Received via mailing list)
I know I've seen this somewhere before, but my friend Google and I just
can't seem to recall where.

I would like to change the style of a link (in my application layout)
based
upon which controller is currently active.

This is what I have, which doesn't work:

<%= link_to "Part", part_path, :class => @controller.name == "parts" ?
'selectedmenu' : 'unselectedmenu' %>

I'm sure I've seen this sort of construct in the past, but I can't
recall
how to construct it.  Specifically, this bombs because name is
undefined.  I
can probably figure that one out myself.  More generally, is there a
nice
helper method defined to select a specific class based on the
controller?

--wpd
This topic is locked and can not be replied to.