I just watched the railscasts for multistep forms, and I now have a multistep form that works great when creating a new instance, but updating and editing does not work, it does the multistep but when I click continue on the last step it just does not update, and it seems the session gets lost…
This is the controller… If I use
session[:location_params].deep_merge!(params[:location]) if params[:location]
an error happens that states that deep_merge cannot be done…
def edit
@location = Location.find(params[:id])
session[:location_params] = @location
@location.current_step = session[:location_step] = @location.steps.first
end
def update
@location = Location.find(params[:id])
@location.current_step = session[:location_step]
if params[:back_button]
@location.previous_step
elsif @location.last_step?
@location.save if @location.all_valid? and @location.changed?
else
@location.next_step
end
session[:location_step] = @location.current_step
if @location.created_at_changed?
flash[:success] = "Location updated!"
session[:location_step] = session[:location_params] = nil
redirect_to @location
else
render 'edit'
end
end
Thank you for your help and guidance.
I ended up using FormToWizard jquery library, you can download it here.
Its cleaner and makes the views very clean to work with and easily maintenable, does not change anything on the controllers!