Search code examples
javascriptruby-on-rails-3.1

providing an image for button_to in rails 3


Is there any way to change the provide an image for the button in the following code

<%= button_to 'Edit treatment', edit_treatment_path(@treatment), :type => "submit", :class => "style3", :method => "get" %>

Solution

  • If you are trying to submit a form by image click (assuming that since your type is "submit") you can use

    image_submit_tag("your_image.png", :class => "style3")
    

    If you meant a standard button you can use

    link_to image_tag("your_image.png"), edit_treatment_path(@treatment), :class => "style3"