# Passing un-editable model attributes from a form

**URL:** <https://www.ruby-forum.com/t/passing-un-editable-model-attributes-from-a-form/89638>\
**Category:** Rails\
**Created:** [March 21, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/passing-un-editable-model-attributes-from-a-form/89638 "2007-03-21T20:25:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathaniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@Nathaniel](https://www.ruby-forum.com/u/Nathaniel)\
**Post date:** [March 21, 2007, 8:25pm UTC](https://www.ruby-forum.com/t/passing-un-editable-model-attributes-from-a-form/89638/1 "2007-03-21T20:25:27Z")

</div>

Dear anyone,

I’m trying to create a very simple “form\_for” form which, when  
submitted, will create, via a RESTFUL controller, a new model  
object…all exactly as per the scaffold\_resource-generated  
model/controller/view but with one difference:

At the time the form is generated, I compute the appropriate value for 2  
of this model’s 3 columns based on instance variables floating around at  
that time (they depend on the view the user is being presented with)

The form presents the user with the remaining 1 attribute to fill in.

Upon submission, how do I get my 2 predetermined values to the  
controller within the standard params[:model\_name] hash? I don’t want to  
set my 2 attributes within the controller, as I want the controller  
“create” action to remain more generic than that.

I imagine this is trivial…if you know how!

Many thanks, Nathaniel

---

<div class="post-metadata">

**Author:** ![Nathaniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@Nathaniel](https://www.ruby-forum.com/u/Nathaniel)\
**Post date:** [March 21, 2007, 8:50pm UTC](https://www.ruby-forum.com/t/passing-un-editable-model-attributes-from-a-form/89638/2 "2007-03-21T20:50:32Z")

</div>

Look them up when you are generating the html form (if they are in a  
DB) and pass them back as hidden fields in the form.

On Mar 21, 2:25 pm, Nathaniel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Nathaniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@Nathaniel](https://www.ruby-forum.com/u/Nathaniel)\
**Post date:** [March 21, 2007, 9:02pm UTC](https://www.ruby-forum.com/t/passing-un-editable-model-attributes-from-a-form/89638/3 "2007-03-21T21:02:18Z")

</div>

Andrew, Matthew,

Thanks to both of you. “form.hidden\_field” is exactly what I was  
after—I was ignorant to its existence!

3 hours wasted this afternoon; fixed in 3 minutes with your help.

Thanks again

Nathaniel

---

<div class="post-metadata">

**Author:** ![Nathaniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@Nathaniel](https://www.ruby-forum.com/u/Nathaniel)\
**Post date:** [March 21, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/passing-un-editable-model-attributes-from-a-form/89638/4 "2007-03-21T20:53:53Z")

</div>

Nathaniel wrote:

> The form presents the user with the remaining 1 attribute to fill in.
> 
> Upon submission, how do I get my 2 predetermined values to the  
> controller within the standard params[:model\_name] hash? I don’t want to  
> set my 2 attributes within the controller, as I want the controller  
> “create” action to remain more generic than that.

You mean other than just using hidden fields like so:  
form.hidden\_field(:some\_predefined\_attr). You just have to fill in the  
value for :some\_predfined\_attr in the object before you run your  
form\_for on it.

-matthew
