Hello! I am using the standard (scaffolded), REST routing. I need to pass external values to my "new" action for a certain model, and let the user complete the other fields in the standard form_for. My initial idea has been to simply amend the URL like this: .../foos/new?size=4&weight=2 Then in the controller I just do something like: def new @temp = Foo.new @temp.size = params[:size] ... respond_to do |format| format.html format.xml { render :xml => @temp } end end Thing is my form_for parameters are not picked up. Only the ones I have setup manually in the URL (size and weight in my example) are taken into account. I believe it is due to the fact that they are serialized and added to the end of the URL, whereas it already contains a "?" and some parameters so they end up being ignored. Do you know how to do this? Thanks! PJ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Jan 19, 2012 at 4:19 PM, PierreW <wamrewam-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I am using the standard (scaffolded), REST routing. I need to pass > external values to my "new" action for a certain model, and let the > user complete the other fields in the standard form_for. > My initial idea has been to simply amend the URL like this: > > .../foos/new?size=4&weight=2Why don''t you include them in the form as hidden fields? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Hassan. Sorry I did not give the context: these links are used by another, external app (say app B). A user of app B can trigger the creation of a record in App A, and it needs to pass some default parameters. So I don''t believe I can use the standard method of using hidden fields, can I? So the idea really is: how can you create entry points to an app where these entry points contain default parameters for the creation of a record? It seems to me these parameters HAVE to be passed with the URL, but maybe I am wrong? Thanks! On Jan 20, 12:55 am, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jan 19, 2012 at 4:19 PM, PierreW <wamre...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > I am using the standard (scaffolded), REST routing. I need to pass > > external values to my "new" action for a certain model, and let the > > user complete the other fields in the standard form_for. > > My initial idea has been to simply amend the URL like this: > > > .../foos/new?size=4&weight=2 > > Why don''t you include them in the form as hidden fields? > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 20, 2012 at 12:18 AM, PierreW <wamrewam-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Sorry I did not give the context: these links are used by another, > external app (say app B). A user of app B can trigger the creation of > a record in App A, and it needs to pass some default parameters.OK, so to make sure I understand: app B has a link to appA/foos/new?size=4&weight=2 -- correct? and then appA''s foos `create` action should include those additional parameters passed to `new`? If so, there''s no reason you couldn''t conditionally add hidden inputs to your `new` form to be processed as part of the `create`. Please let me know if I''m totally off base on my understanding :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Your understanding is absolutely right. My initial gut was indeed to try hidden inputs. But it does not work: App B calls appA/foos/new?size=4&weight=2 App A foo/new method is called and the form is pre-populated with size and weight. The problem is, the URL is still appA/foos/new?size=4&weight=2. When the form is submitted, I think what happens is Rails tries to append the form parameters to the existing URL. Since that URL already contains parameters it does something like: appA/foos/new?size=4&weight=2?size=4&weight=2&price=10 etc and the second set of parameters after the second "?" is ignored by the browser. At least that''s my understanding (I could be wrong). I guess it would work if I could remove the first set of params. But it looks like I will need to do a redirect_to. I was thinking there might be a cleaner way. Sorry it is a bit convoluted... Thanks! PJ On Jan 20, 4:00 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Jan 20, 2012 at 12:18 AM, PierreW <wamre...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > Sorry I did not give the context: these links are used by another, > > external app (say app B). A user of app B can trigger the creation of > > a record in App A, and it needs to pass some default parameters. > > OK, so to make sure I understand: > > app B has a link to appA/foos/new?size=4&weight=2 -- correct? > > and then appA''s foos `create` action should include those additional > parameters passed to `new`? > > If so, there''s no reason you couldn''t conditionally add hidden inputs > to your `new` form to be processed as part of the `create`. > > Please let me know if I''m totally off base on my understanding :-) > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Jan 20, 2012 at 10:35 AM, PierreW <wamrewam-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> App A foo/new method is called and the form is pre-populated with size > and weight. > The problem is, the URL is still appA/foos/new?size=4&weight=2. When > the form is submitted, I think what happens is Rails tries to append > the form parameters to the existing URL.Sorry, that makes no sense -- the submission URL (that will go to the `create` action) shouldn''t contain anything from the `new` request. What is your view code for the start of the form, and what does using `view source` show you for that? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan,> Sorry, that makes no sense -- the submission URL (that will go to the > `create` action) shouldn''t contain anything from the `new` request.You are absolutely right... I got totally confused. I looked at my form again and indeed the problem was in it. Thanks a lot for pointing me in the right direction. PJ On Jan 20, 6:55 pm, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Jan 20, 2012 at 10:35 AM, PierreW <wamre...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > App A foo/new method is called and the form is pre-populated with size > > and weight. > > The problem is, the URL is still appA/foos/new?size=4&weight=2. When > > the form is submitted, I think what happens is Rails tries to append > > the form parameters to the existing URL. > > Sorry, that makes no sense -- the submission URL (that will go to the > `create` action) shouldn''t contain anything from the `new` request. > > What is your view code for the start of the form, and what does using > `view source` show you for that? > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.