I am trying to make my rails form_for
submit button look like the bootstrap btn btn-lg btn-primary
button. I've tried a few different ways and have found no success. The best I could get is getting the form_for
submit button in the center of a bootstrap button with different colors. Does anyone know what the command would be to get the bootstrap button to perform the action that my f.submit
button does.
<div class="Action">
<%= f.submit %>
</div>
= f.submit :Submit, class: 'btn btn-success'
By default <%= f.submit %>
will create an <input>
element according to the docs.
If you want to make it an actual <button></button>
element, you can do it like this:
<%= f.button "My Button", type: "submit", :class=> "btn btn-primary" %>
Not clear from the docs: if you still want the form_for to set the button name to 'Update <class>
' or 'Create <class>
' then pass nil
into the submit:
<%= form.submit nil, class: 'btn btn-success' %>
= f.submit :Submit, class: 'btn btn-success'
or
= f.submit :Submit, class: :btn, class: :btn-success
Anyone getting errors on:
undefined local variable or method 'f'
Check what your form variable name is. It will appear when you're declaring a form such as:
form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With