I'm developing in rails right now and I was wondering if there are any easy ways to add some style to the button_to control.
Can you add styling to the
<%= submit_tag 'Log in' %>
or
<%= button_to "Show Me", {:controller => 'personal', :action => "add" } %>
It would be great to change the color....But brownie point if someone can tell me how to make it an image
Since you're using an image, there is no reason to use button_to
instead of link_to
, "button look" will be lost to the user. You can create an image with a link like so:
<%= link_to image_tag("rails.png"), {:controller => 'foo', :action => "bar" } %>
If, for some reason, you need to use button_to, you can give it a CSS class and apply some styles via that:
<%= button_to "Show Me", {:controller => 'personal', :action => "add" }, {:class => "buttonTo" } %>
In addittion to Mike's very fine pointer to using a pre-defined :class
, you can also go for :style
and define the CSS inline. Helps a great deal if you want to define your style on the fly:
<%= button_to "Show Me", {:controller => 'personal', :action => "add" }, {:style => "background: #{obj.colourname}" } %>
(With obj
being some model instance that stores some HTML colour value at the colourname
attribute.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With