2 submit buttons in a form

前端 未结 3 972
感动是毒
感动是毒 2020-12-31 19:05

I have a question about forms. I have a fairly standard form that saves a post (called an eReport in my app) with a title and body. The table also has a \"published\" field,

3条回答
  •  暖寄归人
    2020-12-31 19:34

    I don't know about formtastic, but with the default rails form builder, you could do it like this:

    <%= form.submit "Save with option A", :name => "save_option_a" %>
    <%= form.submit "Save with option B", :name => "save_option_b" %>
    

    Then in the controller, you can pick those up in params:

    if params[:save_option_a]
      # do stuff
    end
    

提交回复
热议问题