# If on certain page display, else display

**URL:** <https://www.ruby-forum.com/t/if-on-certain-page-display-else-display/148144>\
**Category:** Rails\
**Created:** [September 9, 2008, 7:31pm UTC](https://www.ruby-forum.com/t/if-on-certain-page-display-else-display/148144 "2008-09-09T19:31:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [September 9, 2008, 7:31pm UTC](https://www.ruby-forum.com/t/if-on-certain-page-display-else-display/148144/1 "2008-09-09T19:31:48Z")

</div>

Hello, first off sorry i am new and a dumbass but I need help with  
this.

In my view/application file i have some css and I want a certain bit  
of css displayed if a user is in one controller but another type of  
css to be display if they are in another controller. I made up the  
following which totally doesnt work.

\<% if :controller =\> ‘pages’, :action =\> ‘index’ , :action =\> ‘about’  
%\>

```
<% else %>

<div id='other'></div>

<% end %>

```

If you know of a way to make this work so that certain css is  
displayed when a user is on the home page and about page, but then the  
css changes when they are on any other page I would greatly appreciate  
it.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [September 9, 2008, 7:37pm UTC](https://www.ruby-forum.com/t/if-on-certain-page-display-else-display/148144/2 "2008-09-09T19:37:30Z")

</div>

Dan P. wrote:

> Hello, first off sorry i am new and a dumbass but I need help with  
> this.
> 
> In my view/application file i have some css and I want a certain bit  
> of css displayed if a user is in one controller but another type of  
> css to be display if they are in another controller. I made up the  
> following which totally doesnt work.

Why not create a layout for each controller? That way you don’t need the  
if statements at all, you can just have the layout use whatever layout  
ue specify.

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [September 9, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/if-on-certain-page-display-else-display/148144/3 "2008-09-09T19:44:09Z")

</div>

Yeah I guess I can do that, but its just I didn’t want to have to  
create a new layout just for one simple line of code. But thanks for  
the suggestion if I cant find a way to do it I will do it that way.

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [September 9, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/if-on-certain-page-display-else-display/148144/4 "2008-09-09T19:48:51Z")

</div>

found the answer if anyone else is looking for it

\<% if controller.controller\_name == “pages” %\>

```
<% else %>

<div id='other'></div>

<% end %>
```
