I implemented a multistep form with the method described by Ryan Bates in ep217 but I had some weird behavior when refreshing or moving between the steps Acts_as_good_style (old but still good) has a tip redirect when moving on that lead me to the change in the code that follows.
In a nutshell, it says that if you're in the
create action you should not render
new (as I was doing).
This solved the problem. But I had to manage the case of errors in the form, so I ended up with this code.
#profiles_controller.rb def create # [...] save etc [...] # render if @profile.new_record? # render 'new' # OLD session[:profile_valid] = @profile.errors.blank? # NEW redirect_to new_profile_path # NEW else # [...] end end def new @profile = Profile.new(session[:profile_params]) # [...] # rebuild errors (see create) # check false because first time is nil and no error have to be displayed @profile.valid? if session[:profile_valid] == false session[:profile_valid] = true end
Where in the
new action I reload the errors otherwise lost depending on
session[:profile_valid], that works fine.
BUT this way doesn't look very good to me and I would appreciate to have your opinion, OR how do you manage your controllers in multispets forms?
What was the strange behavior? Refreshing or going back and forth through the steps sometimes you jump to the wrong page, not clear what the logic is, probably depends on the validations in the model and the params hash.