Ben Downey
Ben Downey

Reputation: 2665

Rails: how to style submit tag with custom css

The code below creates a form and styles the "submit" button according to some css ("button"). The problem is, when the page renders, it shows the normal rails submit tag button on top of the customized "button" css. How do I mute or disable the visual aspects of the rails submit tag button while still making it submit the form?

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

Upvotes: 6

Views: 11748

Answers (4)

copremesis
copremesis

Reputation: 776

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>

Upvotes: 1

Max Alexander Hanna
Max Alexander Hanna

Reputation: 3871

I'm using old school ruby(1.8.7) and rails(2.3.5)

heres what my submit tags look like for custom css styling :

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

where "Edit" is the text that appears on the button, and "width:30px;" is my styling. you can also cascade the stylings :

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

Upvotes: 3

alexl
alexl

Reputation: 41

Another way is (rails 4.1)

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

Here is where you go to find answers http://api.rubyonrails.org/

and if you are working in form_for you would do

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

Upvotes: 3

Dougui
Dougui

Reputation: 7230

Could you 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 the css style for the button?

It better to do this :

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

Upvotes: 6

Related Questions