My question is easy:
<%= f.submit %>
Where does the class declaration go? I'm getting errors on multiple attempts.
This question is related to
ruby-on-rails
css
ruby-on-rails-3
By default, Rails 4 uses the 'value' attribute to control the visible button text, so to keep the markup clean I would use
<%= f.submit :value => "Visible Button Text", :class => 'class_name' %>
As Srdjan Pejic says, you can use
<%= f.submit 'name', :class => 'button' %>
or the new syntax which would be:
<%= f.submit 'name', class: 'button' %>
both of them works
<%= f.submit class: "btn btn-primary" %>
and
<%= f.submit "Name of Button", class: "btn btn-primary "%>
You can add a class declaration to the submit button of a form by doing the following:
<%= f.submit class: 'btn btn-default' %>
<-- Note: there is no comma!
If you are altering a _form.html.erb partial of a scaffold and you want to keep
the dynamic change of the button name between controller actions, DO NOT specify a name 'name'
.
Without specifying a name and depending on the action the form is rendered the button will get the .class = "btn btn-default"
(Bootstrap class)(or whatever .class
you specify) with the following names:
Update model_name
Create model_name
(where model_name the name of the scaffold's model)
<%= f.submit, "Submit", class: 'btn btn-primary' %>
Don't forget the comma after the f.submit
method!
HTH!
Source: Stackoverflow.com