Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!"
like image 636
Ben Downey Avatar asked Jul 23 '12 16:07

Ben Downey


4 Answers

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'
like image 100
Dougui Avatar answered Nov 15 '22 01:11

Dougui


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" ) %>
like image 26
alexl Avatar answered Nov 14 '22 23:11

alexl


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;") %>
like image 31
Max Alexander Hanna Avatar answered Nov 15 '22 01:11

Max Alexander Hanna


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>
like image 44
copremesis Avatar answered Nov 15 '22 01:11

copremesis