ruby-on-rails-3buttonformtastic

How can I have multiple commit buttons for a form in formtastic in Rails 3?


I have a form and am using Formtastic. I want to have two options for the button and to store the value selected in the newly created record.

Would I do something like this?

<%= form.buttons do %>
  <%= form.commit_button :value => "Give" %>
  <%= form.commit_button :value => "Request" %>
<% end %>

Solution

  • commit_button() takes a first argument as a String, or, to match the input() API, it also accepts a :label option. These two are functionally equivalent:

    <%= f.commit_button :label => "Save" %>
    <%= f.commit_button :label => "Save and Continue Editing" %>
    
    <%= f.commit_button "Save" %>
    <%= f.commit_button "Save and Continue Editing" %>
    

    There's no APIs yet for cancel buttons, reset buttons, etc. You can also use standard Rails helpers like link_to and puts some mark-up around them:

    <%= f.buttons do %>
      <%= f.commit_button :label => "Save" %>
      <li class="cancel">
        <%= link_to "Cancel", foos_path %>
      </li>
    <% end %>