Rails - Building a Wizard . Where to start, where to store
I'm interested in building a wizard for my web app that users use when they first login in that has 3 simple steps:
- Upload profile photo
- Profile Info
- Find Friends
That kind of thing. so my question is how do I do this with Rails?
The GettingStarted will essentially have the 3 views above. With Next/Back/Skip buttons. Where do I submit? How do I track the current view and decide how to show the next view?
I realize this is a bigger/broader question and appreciate any high level thinking you can share on how to smar开发者_如何学Pythontly handle this.
Thank you!
Some considerations must be made before ultimately deciding on a solution. For instance, must this wizard be completed before moving on to the actual application, or is it something that can be entirely bypassed by (for example) signing in from a different computer?
Assuming it's ok to bypass it, I would create a namespace (for instance, getting_started) with three nested resources: photo, profile, and friends. There is really no need to track which step a user is on, as you can simply forward from one step to the next after submission, and add back and skip buttons where necessary.
The most important point, though, is to namespace this wizard and avoid polluting the "normal" controllers for these resources with wizard-specific actions. In this way, things stay REST-ful and organized.
Routes might look something like:
namespace :getting_started do
resource :photo, :only => [:edit, :update]
resource :profile, :only => [:edit, :update]
resources :friends, :only => [:index, :create]
end
Have a look at this railscasts. I imagine it will be a good starting point for you.
http://railscasts.com/episodes/217-multistep-forms
精彩评论