Search code examples
ruby-on-rails-3.1formtastic

More than one submit button on a form


I have a form that I am building in formtastic which is for more than one model.

This form is for one model with multiple nested models, but each section is separated using css and javascript, but I have a submit button on each section.

How can I modify the action for each of those buttons so that I can let the controller know which section the post is from (for redirection to the next section)

The basic solution I can think of is to have separate semantic_form_for tags going to the same action, with a different hidden field called section

Would it be the best way to approach this?


Solution

  • You may want to try simple_form, which is a more current replacement for formtastic and is also fully compatible with Rails's own form helpers. You can then specify different commit names for each button, e.g.:

    f.button :submit_section1
    
    f.button :submit_section2