# How to exclude field from edit

**URL:** <https://www.ruby-forum.com/t/how-to-exclude-field-from-edit/88008>\
**Category:** Rails\
**Created:** [March 7, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/how-to-exclude-field-from-edit/88008 "2007-03-07T14:58:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ned.c.amazotz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@ned.c.amazotz](https://www.ruby-forum.com/u/ned.c.amazotz)\
**Post date:** [March 7, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/how-to-exclude-field-from-edit/88008/1 "2007-03-07T14:58:34Z")

</div>

I’d like to exclude certain fields from rails’ edit view. I want the  
value of these fields to be calculated by the database. I’d like the  
value visible in rails, but I’d like to hide the field when in edit  
mode. Can I do this? How?

TIA.

---

<div class="post-metadata">

**Author:** ![ned.c.amazotz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@ned.c.amazotz](https://www.ruby-forum.com/u/ned.c.amazotz)\
**Post date:** [March 7, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/how-to-exclude-field-from-edit/88008/2 "2007-03-07T15:10:37Z")

</div>

On Wed, Mar 07, 2007 at 05:53:42AM -0800, ned.c.amazotz wrote :

> I’d like the  
> value visible in rails, but I’d like to hide the field when in edit  
> mode. Can I do this? How?

You can access in your view to controller.action\_name. So you could  
write a my\_text\_field(params) helper working like:

controller.action\_name != ‘edit’ ? text\_field(params) :  
hidden\_field(params)

Hope I’ve understood your problem.

–  
,========================.  
| Pierre-Alexandre M. |  
| email : removed\_email\_address@domain.invalid |  
`========================’

---

<div class="post-metadata">

**Author:** ![ned.c.amazotz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@ned.c.amazotz](https://www.ruby-forum.com/u/ned.c.amazotz)\
**Post date:** [March 7, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/how-to-exclude-field-from-edit/88008/3 "2007-03-07T16:35:54Z")

</div>

On Mar 7, 2007, at 2:53 PM, ned.c.amazotz wrote:

> I’d like to exclude certain fields from rails’ edit view. I want the  
> value of these fields to be calculated by the database. I’d like the  
> value visible in rails, but I’d like to hide the field when in edit  
> mode.

The programmer chooses the fields to show in a form. In you are using  
scaffolding you’ll need to adapt the edit view to your needs.

On the other hand, if in addition you need to ensure users don’t  
inject values in that field have a look at attr\_protected and, in  
recent Rails, attr\_readonly.

– fxn
