I am building an application that requires a 2-step process for creating an object for one of the models.
I have considered...
creating a custom route to the custom "new" action
or
using the same "new" action for both steps but render the correct view based on a param
What is the best way to handle this?
In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as. map.resources :photos. creates seven different routes in your application: HTTP verb.
Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.
TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.
Have a look at this screencast for a multistep form.
http://railscasts.com/episodes/217-multistep-forms
Ryanb is using a nice way with the validations for each step and keeping everything in the create action so no need to have extra routes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With