# How to select a style based on the controller?

**URL:** <https://www.ruby-forum.com/t/how-to-select-a-style-based-on-the-controller/155439>\
**Category:** Rails\
**Created:** [December 11, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/how-to-select-a-style-based-on-the-controller/155439 "2008-12-11T19:33:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [December 11, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/how-to-select-a-style-based-on-the-controller/155439/1 "2008-12-11T19:33:22Z")

</div>

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
