# Which action?

**URL:** <https://www.ruby-forum.com/t/which-action/115592>\
**Category:** Rails\
**Created:** [September 26, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/which-action/115592 "2007-09-26T17:49:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DuzenburyS\_Rich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@DuzenburyS\_Rich](https://www.ruby-forum.com/u/DuzenburyS_Rich)\
**Post date:** [September 26, 2007, 5:49pm UTC](https://www.ruby-forum.com/t/which-action/115592/1 "2007-09-26T17:49:45Z")

</div>

Hi,

I’ve got a partial that I call from more than one view. I need it to be  
slightly different when called from one of the views. Does rails set a  
variable to tell the partial which action or view is calling it, and if  
so, how?

Thank you.

Regards,  
Rich

---

<div class="post-metadata">

**Author:** ![DuzenburyS\_Rich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@DuzenburyS\_Rich](https://www.ruby-forum.com/u/DuzenburyS_Rich)\
**Post date:** [September 26, 2007, 6:53pm UTC](https://www.ruby-forum.com/t/which-action/115592/2 "2007-09-26T18:53:45Z")

</div>

You can get the action from the params hash, params[:action]

Duzenbury, Rich wrote:

> Rich
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![DuzenburyS\_Rich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@DuzenburyS\_Rich](https://www.ruby-forum.com/u/DuzenburyS_Rich)\
**Post date:** [September 26, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/which-action/115592/3 "2007-09-26T22:04:16Z")

</div>

Hi,

\<%= controller.action\_name %\>

Thanks.

Regards,  
Rich

---

<div class="post-metadata">

**Author:** ![DuzenburyS\_Rich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@DuzenburyS\_Rich](https://www.ruby-forum.com/u/DuzenburyS_Rich)\
**Post date:** [September 26, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/which-action/115592/4 "2007-09-26T22:27:41Z")

</div>

On 9/26/07, Duzenbury, Rich [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I’ve got a partial that I call from more than one view. I need it to be  
> slightly different when called from one of the views. Does rails set a  
> variable to tell the partial which action or view is calling it, and if  
> so, how?

You’ve figured out how to get the action name, but I would suggest  
that this technique tends to make your code very “brittle”. A better  
approach might be to pass a variable to the partial through the call  
to render() using the :locals option.
