With an image?

Hey guys, I'm trying to create an image button. So basically, I need a version button for the code below: |

<%= link_to image_tag(product.image_url, :class => "img"), line_items_path(:product_id => product) %> 
+4
source share
6 answers

This is my decision:

Use the helper element (you can use the button_to helper method):

 <%= f.submit 'Save', :class => "button_with_image_save" %> 

CSS

 .button_with_image_save { background: url(../images/icons/page_save.png) #f2efa8 no-repeat 10px 6px; text-indent:30px; display:block; cursor: pointer; } 
+1
source

This is a pretty old post, but for future reference: since Rails 3.2.1 you can use button_tag instead of button_to , since the first one allows images:

Creates a button element that defines a submit button, a reset button, or a generic button that can be used, for example, in JavaScript. You can use the button tag as a regular submit tag, but it is not supported in older browsers. However, the button tag allows you to use brighter shortcuts, such as images and highlighting, so this assistant will also accept the block.

As for your example:

 <%= button_tag image_tag(product.image_url), line_items_path(:product_id => product), class: 'img' %> 

I have not tested the code, but it should work. Maybe you need to declare the URL using url:

+1
source

You can create helper as button_to link -

 <%= button_to product.image_url, line_items_path(:product_id => product) %> 

and in application_helper

 def button_to(image_path, link) link_to (image_tag(image_path, :class => "img"), link) end 

I think this is what you want.

0
source

The short answer is that you need to create a helper method that is pretty simple:

Here is a similar SO post explaining this: Is there a way with a helper to create button tags to send

Good luck.

0
source

Image Submit Button:

 <%= image_submit_tag("team/team1.png", class: 'image-responsive') %> 

Image Link:

 <%= link_to(image_tag("team/team1.png", class: 'image-responsive'), root_path, :method => :get) %> 
0
source

Add image is the app / assets / image folder

In view

 <%= image_submit_tag('nameimage.png') %> 

the disadvantage is that you cannot resize with the size, but you must have an image of the size you want to display

0
source

All Articles