Form with multiple submit buttons
When you need to use the form in rails with submitting to different URL, you probably will try to handle it with js.
Now you don’t need to, just use formaction
on submit button. The formaction
override the URL in form action and used its own.
<%= form_for @article, url: {action: "create"} do |f| %>
<%= f.text_field :title %>
<%= f.text_area :body, size: "60x12" %>
<%= f.submit "Create" %> #this will use URL from form
<%= f.submit "Create Draft Article", formaction: '/draft_articles' %> #this will use URL from formaction
<% end %>
Tweet