Melbourne2991
Melbourne2991

Reputation: 11797

image_tag not working for external URL, returns object

Unfortunately the below is not working for me @shps is a list of urls.

<h1>Shewps</h1>
<% @shps.each do |shp| %>
<%= image_tag(shp) %>
<% end %>   

The HTML I get is as follows:

<img alt="#&lt;shp:0xa0c5af8&gt;" src="/assets/#&lt;Shp:0xa0c5af8&gt;">

It seems shp is returning an object?, when i use shp outside of the image tag it returns as a string. Also it is looking in ./assets/ when it is an external url.

Upvotes: 0

Views: 825

Answers (2)

Melbourne2991
Melbourne2991

Reputation: 11797

Turns out I needed to call shp.url , url being one of the attributes for my model. shp returns the entire object.

Upvotes: 0

Marek Lipka
Marek Lipka

Reputation: 51151

Instead of passing ActiveRecord object, you should pass actual url to image_tag method. So, assuming you store it in url column:

<% @shps.each do |shp| %>
  <%= image_tag shp.url %>
<% end %>

Upvotes: 2

Related Questions