Co2 Co2 - 10 months ago 59
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" } %>




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.