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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With