Co2 Co2 - 2 years ago 153
HTML Question

Ruby on Rails, image link sizing

I have two images as links on a page. Problem is they are both different sizes. Is there an easy way to resize the images here?

<div class="col-sm-4"><%= link_to image_tag("image1.jpg"), {:controller => 'customers', :action => "new" } %>

<h3>BOOK A TOUR</H3>
<div class="col-sm-4">
<%= link_to image_tag("image2.jpg"), {:controller => 'tours', :action => "index" } %>



Answer Source

You can set image size with size property. Let's assume your images are 100 pixels wide and 20 pixels tall. Then you would specify it like this:

image_tag("image1.jpg", size: "100x20")

# Generates
# => <img src="/assets/image1.jpg" width="100" height="20" alt="" />

And your link code would be:

link_to image_tag("image1.jpg", size: "100x20"), {:controller => 'customers', :action => "new" }

PS. Consider using alt attribute in your images.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download