Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image_tag in Ruby on Rails allows me to change the "Size" parameter but not "height/width" parameters

Problem: I am currently doing an assignment for a Ruby on Rails course in which I need to pull information from the Coursera API and display it in an organized table. The exact problem is the pictures in their database is huge, so I was forced to resize it inside the image_tag. I was having trouble because "height" and "width" parameters were giving me syntax errors, so I tried the "size" parameter with the same syntax and it worked!

Original line of code:

<td><%= image_tag(course["photoUrl"])%></td>

Which pulled the photo without a problem from the course Hash.

Working code with fixed size:

<td><%= image_tag(course["photoUrl"], size: "250")%></td>

Which indeed, fixed the size of the image quite nicely.

Code that I don't understand why it does not work:

<td><%= image_tag(course["photoUrl"], height: "250" width: "350")%></td>

Documentation: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag

like image 443
Jordan Mack Avatar asked Sep 11 '25 19:09

Jordan Mack


1 Answers

You are just missing a comma (,) between the width and height parameters.

<td><%= image_tag(course["photoUrl"], width: "350", height: "250")%></td>

Alternatively, you could still use the size attribute like so:

<td><%= image_tag(course["photoUrl"], size: "350x250")%></td>
like image 169
The F Avatar answered Sep 13 '25 11:09

The F