我用由三个步骤组成的 wicked-gem 构建了一个多步骤表单。
最后一步应该可以调用 1 到 x 次。
所以我在表单中添加了另一个按钮:
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'
并在我的控制器中添加另一个步骤
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
最后需要的步骤是:add_principal_claim。如有必要,应多次调用它以将多个数据集存储到模型中。
从前面的步骤调用表单会导致显示操作并呈现 add_principal_claim 视图,单击 file.submit 按钮会导致控制器中的更新操作,将数据集存储到模型中并按预期调用 add_principal_claim 视图。
如何让 link_to 按钮跳转到更新操作、存储数据集然后最终跳出向导?
任何建议将不胜感激。