That's just it, you don't. You POST to the collection, which `create`s a new 
instance. 

If you are expecting the GET with a querystring to create a new form with a 
picker selected, you should start by creating the form all in one piece, where 
you create a new form including a select (like the one you are trying to divide 
across two pages) in that same form. Make sure that submitting that form works, 
even though it doesn't do precisely what you're asking it to do in the divided 
form (yet).

Then figure out how to set that property (which the select chooses) on the 
`new` controller method.

There's a couple of different ways to do that. One would be to create a 
completely hand-made variable that you pass in the querystring of the form:

/items/new?item_type=Foo

and then "catch" that in the controller in the new method:

@item = Item.new(item_type = params[:item_type])

The other would be to go full-on REST, and create a new instance in the 
`index`, use that to build your form, and then you can use the regular 
strong_params accessor to get that same value (which will be "nested" inside a 
properly-named instance params hash) and assign it to the instance in the `new` 
method.

Now, what you should see at this point is that your all-in-one `new` form 
begins to behave "automatically". The instance that you build in the controller 
will be populated with the item_type property, and the picker will auto-select 
to the chosen value. 

Once you see this working, you can change the select (picker) to a hidden 
field, and with no other changes, you will have your two-step form.

Walter

> On Dec 1, 2019, at 12:17 PM, fugee ohu <fugee...@gmail.com> wrote:
> 
> Thanks but since when do we post to the new action? 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/fd3f5207-840b-4fec-ba29-100fdf882447%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/F38B1785-69F3-40DE-8E24-3C660B78A51D%40wdstudio.com.

Reply via email to