Rails: how to create a submit tag with custom css

In the code below, a form is created and the "submit" button is styled in accordance with some css ("button"). The problem is that when the page is displayed, it shows the usual button for sending rails tags on top of the configured "button" css. How to disable or disable the visual aspects of the submit button for rails tags, but submit the form?

=form_tag new_site_url, :method => :get do
  =text_field_tag :homepage,'', type: "text", class: 'text'
  %button
    =submit_tag "GO!"
+5
source share
4 answers

You could do this:

=form_tag new_site_url, :method => :get do
  =text_field_tag :homepage,'', type: "text", class: 'text'
  =submit_tag "GO!", class: 'button'

and set css style for button?

Better to do it:

=form_tag new_site_url, :method => :get do |f|
  =f.text_field '', type: "text", class: 'text'
  =f.submit "GO!", class: 'button'
+6
source

I use an old school ruby ​​(1.8.7) and rails (2.3.5)

heres what my submit tags look like custom CSS style:

<%= submit_tag("Edit", :style => "width:30px;") %>

"" - , , "width: 30px;" . :

<%= submit_tag("Edit", :style => "width:30px;color:blue;") %>
+2

( 4.1)

<%= submit_tag("Submit", :class => "btn btn-warning" ) %>

Here you will find the answers http://api.rubyonrails.org/

and if you work in form_for you would do

<%= f.submit("Submit", class: "btn btn-default" ) %>
+1
source

You can add a style key to the hash

<p><%= submit_tag l(:button_apply), :class => 'btn btn-default btn-sm', :name => 'submit', :style => 'margin-left: 42px' %></p>
+1
source

All Articles