How to exclude field from edit

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.

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 : [email protected] |
`========================’

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