Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful way to deal with multi-step "new" action in Rails 3

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?

like image 510
Patrick Connor Avatar asked May 05 '11 15:05

Patrick Connor


People also ask

What are RESTful routes in Rails?

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.

What is match in Rails routes?

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.

How do I find routes in Rails?

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.


1 Answers

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.

like image 64
Michael Koper Avatar answered Nov 03 '22 18:11

Michael Koper