1

I really hope you can help me out with this issue. I have managed to pull the picture from my database into the product description, but the picture displayed is way too big and I would like to resize it, but whatever I try it doesn`t include the image to the class.

That`s my index.html.rb

<% @homes.each do |home| %>
  <tr>
    <td width="130px"><%= home.name %></td>
    <td class="image"><%= image_tag "/"+home.images[0].image_path %></td>
    <td width="300px"><%= home.details %></td>
  </tr>

CSS

.image 
    {
    background: yellow;
    width: 200px;
    }

I set the background color to check if the image class is linked correctly and that works fine. I can see the yellow background changing the size, but the picture lies above that class and is completely unimpressed by what I am trying.

I also tried the below instead of the image class with the result that only a little "img_not_found" icon was displayed followed by " height=80px />.

<td width="200px"><img src="<%= image_tag '/'+home.images[0].image_path %>" height=80px /></td>

Does anybody know where I made the mistake?

Many thanks in advance.

Ron
  • 69
  • 2
  • 7
  • Does my answer resolve your issue here, or would you like me to edit it to cover the CSS-case? It was answered in that way because using `:size` is more semantic and eliminates the extra CSS to just do resizing, which is an integral feature of an image tag. – jimcavoli Apr 01 '13 at 21:34
  • Hi Jim, many thanks for that. It works very well. I only had to adjust the image size to keep the proportions. Or is there any way to keep the proportions automatically? – Ron Apr 01 '13 at 21:59
  • Not just via the image_tag since it's not messing around with the image itself directly. Best is to just have your images consistently sized on the back end. If you want though, you can go about trying to access the files in the code to do some math on their dimensions, in which case the answer at http://stackoverflow.com/questions/2450906/is-there-a-simple-way-to-get-image-dimensions-in-ruby may be helpful to you. – jimcavoli Apr 02 '13 at 13:08
  • Thanks Jim, I will stay with your first suggestion as it works well for me. The other stuff may become interesting once I am a bit more experienced with Rails. You already helped me a lot!!! – Ron Apr 02 '13 at 21:20

1 Answers1

0

:size - Supplied as "{Width}x{Height}", so "30x45" becomes width="30" and height="45". :size will be ignored if the value is not in the correct format.

e.g. <%= image_tag "home.gif", :size => "50x20" %>

For you:

<%= image_tag "/"+home.images[0].image_path, :size => "50x20" %>
jimcavoli
  • 854
  • 9
  • 22