# Name of action inside template

**URL:** <https://www.ruby-forum.com/t/name-of-action-inside-template/61603>\
**Category:** Rails\
**Created:** [May 25, 2006, 3:29pm UTC](https://www.ruby-forum.com/t/name-of-action-inside-template/61603 "2006-05-25T15:29:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 25, 2006, 3:29pm UTC](https://www.ruby-forum.com/t/name-of-action-inside-template/61603/1 "2006-05-25T15:29:28Z")

</div>

Hi all,

How do I know the name of the action currently invoked inside RHTML  
template?  
I need to make a text\_field readonly when the action is ‘edit’ and  
readwrite when the action is ‘new’.

Tq,  
John

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 25, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/name-of-action-inside-template/61603/2 "2006-05-25T16:42:15Z")

</div>

Hi John,

John I. wrote:

> How do I know the name of the action currently invoked inside RHTML  
> template? I need to make a text\_field readonly when the action is ‘edit’  
> and readwrite when the action is ‘new’.

I may be completely misunderstanding your question, but…

In Rails, you will have a seperate view (RHTML template) for each  
controller  
action. So you’ll have a ‘new.rhtml’ and an ‘edit.rhtml’ and you’ll  
just  
include a contentEditable=false attribute on the field in your  
‘edit.rhtml’.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 25, 2006, 6:38pm UTC](https://www.ruby-forum.com/t/name-of-action-inside-template/61603/3 "2006-05-25T18:38:37Z")

</div>

John I. wrote:

> How do I know the name of the action currently invoked inside RHTML  
> template?  
> I need to make a text\_field readonly when the action is ‘edit’ and  
> readwrite when the action is ‘new’.

\<% if controller.action\_name == ‘edit’ -%\>

etc.

–

Ray

---

<div class="post-metadata">

**Author:** ![John\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@John\_I](https://www.ruby-forum.com/u/John_I)\
**Post date:** [May 26, 2006, 7:19am UTC](https://www.ruby-forum.com/t/name-of-action-inside-template/61603/4 "2006-05-26T07:19:01Z")

</div>

Ray B. wrote:

> \<% if controller.action\_name == ‘edit’ -%\>

Thanks Ray!  
Another way I managed to find myself is:  
\<% if params[:action] == ‘edit’ -%\>

> Ray

John
