Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 410
Billy Avatar asked Oct 22 '14 02:10

Billy


4 Answers

= f.submit :Submit, class: 'btn btn-success'
like image 120
OneChillDude Avatar answered Nov 15 '22 14:11

OneChillDude


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

like image 21
ricks Avatar answered Nov 15 '22 15:11

ricks


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' %>
like image 2
phil Avatar answered Nov 15 '22 14:11

phil


= 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|
like image 1
Zitzabis Avatar answered Nov 15 '22 14:11

Zitzabis