jeffp/wizardly

How can I edit an existing resource on a specific stage?

Opened this issue · 2 comments

Hi! Thanks for your plugin.

How can I edit an existing resource on a specific stage? Imagine I have the stages :stage1, :stage2, :stage3. I fill all the stages and the object is created. I then want to re-edit on :stage2. Is it possible?

Easiest is to create a :stage4, and save the model instance in :stage3:

on_next(:stage3) do
  @model_name.save
end

Otherwise, you'll have to set up some routing. Try the following.

on_finish(:stage3) do
  do_not_complete
  @model_name.finished = true
  @model_name.save  #or save_without_validation
  redirect_to :stage2
end

on_next(:stage2) do
  if @model_name.finished
    complete_wizard(your_redirect_here)
  end
end

In this method, you'll have to add a field to detect that :stage3 has been completed, I called it 'finished' and used a boolean defaulting to false. The 'do_not_complete' method tells the wizard to maintain its knowledge of the current model when the user presses finish, this allows you to re-enter :stage2 and work on the same model instance. We call 'complete_wizard' here if this is the second time through.

Let me know what works.

Hi Jeff,

Would there be a way to edit an existing resource without depending on an existing session? say a user decides to complete the form from another computer, thus creating a new session, and I give him a login owning the resource - is there a way to pass this resource to the wizardly controller?