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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
andrew.ohnstad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-21 19:49 UTC
Re: Passing un-editable model attributes from a form
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---