开发者

Rails - Add style/image to button_to

开发者 https://www.devze.com 2022-12-22 00:43 出处:网络
I\'m developing in rails right now and I was wond开发者_如何转开发ering if there are any easy ways to add some style to the button_to control.

I'm developing in rails right now and I was wond开发者_如何转开发ering 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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号