Forum: Ruby on Rails Passing un-editable model attributes from a form

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.
8a3abcfeae74fa0ea68bb23ef0501511?d=identicon&s=25 Nathaniel (Guest)
on 2007-03-21 20:25
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
744b6438d1457d332d1a8d431cc2b641?d=identicon&s=25 andrew.ohnstad@gmail.com (Guest)
on 2007-03-21 20:50
(Received via mailing list)
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 <rails-mailing-l...@andreas-s.net>
3c458017e52f646945b899aa5d380a0f?d=identicon&s=25 Matthew Isleb (misleb)
on 2007-03-21 20:53
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
8a3abcfeae74fa0ea68bb23ef0501511?d=identicon&s=25 Nathaniel (Guest)
on 2007-03-21 21:02
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
This topic is locked and can not be replied to.