Reputation: 1771
I built a multistep form with wicked-gem consisting of three steps.
The last step should be callable 1 to x times.
So I added another button to my form:
if current_step?(:add_principal_claim)
= file.submit value: 'next_claim', class: 'button tiny radius'
= link_to 'finish', Wicked::FINISH_STEP, method: :put, class: 'button tiny radius'
and add another step in my controller
steps :add_file_header, :add_claim_header, :add_principal_claim, :next_principal_claim
def show
if step == :add_claim_header
case step
when :next_principal_claim
redirect_to wizard_path(:add_principal_claim)
else
render_wizard
end
end
end
The last needed step is :add_principal_claim. If neccessary it should be called several times to store more than one dataset to the model.
Calling the form from the previuos step leads into show action and renders the add_principal_claim view, clicking the file.submit button leads to the update action in the controller, stores the dataset into the model and recalls the add_principal_claim view as intended.
How can I get the link_to button to jump into update action, store the dataset and then finally jump out of the wizard?
Any suggestion would be appreciated.
Upvotes: 3
Views: 1181
Reputation: 1771
For those with the same problem: I added another step called :finish and in the form I now have two submit buttons with different values of course, here called 'next_principal_claim' and 'finish'.
def show
if params[:commit] == next_principal_claim
redirect_to wizard_path(:add_principal_claim)
elsif params[:commit] == finish
redirect_to project_path(@project)
else
render_wizard
end
end
That works fine for me!
Upvotes: 0