Forum: Ruby on Rails Name of action inside template

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John Indra (Guest)
on 2006-05-25 15:29
(Received via mailing list)
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
Bill Walton (Guest)
on 2006-05-25 16:42
(Received via mailing list)
Hi John,

John Indra 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
Ray Baxter (Guest)
on 2006-05-25 18:38
(Received via mailing list)
John Indra 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
John Indra (Guest)
on 2006-05-26 07:19
Ray Baxter wrote:
> <% if controller.action_name == 'edit' -%>

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

> Ray

John
This topic is locked and can not be replied to.