# Conditional action - if action = '' do this

**URL:** <https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557>\
**Category:** Rails\
**Created:** [August 8, 2007, 3:59pm UTC](https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557 "2007-08-08T15:59:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [August 8, 2007, 3:59pm UTC](https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557/1 "2007-08-08T15:59:33Z")

</div>

hiya,

trying to work this out to build a dynamic sidebar,

i’ve got the sidebar in a partial, now wondering how to get different  
elements to hide for certain actions…

e.g.

\<% if action = ‘about’ %\>  
about logo  
\<% end %\>

any ideas how you can run conditional parts based on the action you just  
did, or should i set & call a variable instead?

appreciate it,

John.

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [August 8, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557/2 "2007-08-08T16:06:45Z")

</div>

params[:action]

sweet enough?  
🙂

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [August 8, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557/3 "2007-08-08T16:12:23Z")

</div>

Hi –

On Wed, 8 Aug 2007, Shai R. wrote:

> params[:action]
> 
> sweet enough?  
> 🙂

Make sure to use == and not = though…

David

–

- Books:  
RAILS ROUTING (new! [http://www.awprofessional.com/title/0321509242](http://www.awprofessional.com/title/0321509242))  
RUBY FOR RAILS ([Ruby for Rails](http://www.manning.com/black))
- Ruby/Rails training  
& consulting: Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [August 8, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557/4 "2007-08-08T17:07:32Z")

</div>

perfect…

\<% if params[:action] == ‘about’ %\>  
code  
\<% end %\>

you rock!

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [August 8, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/conditional-action-if-action-do-this/111557/5 "2007-08-08T17:05:23Z")

</div>

thanks, it suddenly struck me that i could this this another way.

you see i’ve got the main layout in…

layouts/application.rhtml

so by putting in a code to pull in a partial i could not specify the  
controller to pull it from and then it would pull that partial from the  
controller / view the actions sitting in then and there.

as long as i have the same named partial in each view, pretty sweet.

however thanks for the params[:action] should work out right, yep got  
the == meaning check if identical.

thanks guys,
