Billy
Billy

Reputation: 853

How to make a rails form_for submit button a bootstrap button

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>

Upvotes: 13

Views: 19760

Answers (4)

ricks
ricks

Reputation: 3324

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" %>

Upvotes: 11

phil
phil

Reputation: 4908

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' %>

Upvotes: 2

Zitzabis
Zitzabis

Reputation: 178

= 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|

Upvotes: 1

OneChillDude
OneChillDude

Reputation: 8006

= f.submit :Submit, class: 'btn btn-success'

Upvotes: 22

Related Questions