Images don't show up from show.html.erb

In my app, i’m storing the name of images in the database, and keeping
the images in the /images folder. The index.html.erb for my view uses
an image tag:

 <td><div class="icon"/><img src=<%=h reagent.icon %>/></div></td>

which shows up correctly. attempting to show the same icon in the
show.html.erb doesn’t show the image. adding a border to it shows a
line about the size of a ‘pipe command’ and then the name.

Icon: border=1/> <%=h @reagent.icon %>

i’ve been trying different formats for the last 3 hours with no success.
is there a difference in the references for the two files? or is the
icon just being squashed somehow? I’m using firefox2 on ubuntu 7.10 if
that helps.

You can use image_tag(h.reagent.icon) and that’ll work instead of <img
src=<%= h.reagent.icon %> />

On Sun, Mar 16, 2008 at 12:03 PM, Big Rog
[email protected]
wrote:


Posted via http://www.ruby-forum.com/.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

Ryan B. wrote:

You can use image_tag(h.reagent.icon) and that’ll work instead of <img
src=<%= h.reagent.icon %> />

I’ve only just started using Rails this week, so I’m pretty well lost,
as the tutorials i’ve followed just say “click this then this and it’s
done” instead of delving into why things are done. I’ve tried several
variations of inserting your suggestion into the file, but with no
success. The API listing on railsbrain.com only shows it used for
absolute references, not variable references, so i’m stumped.

did you mean

Icon

<%= image_tag(h.reagent.icon) %>

or

Icon

image_tag(h.reagent.icon)

The first one causes an error (wrong number of arguments (0 for 1)) and
the second one only writes the text of that line to the page. All of
the other references to reagent on the show.html.erb code use <%=h
@reagent. =%> and successfully call their data.

iso … wrote:

Use the first one but remove the dot after the h

h.reagent.icon -> h reagent.icon

<%= image_tag(h reagent.icon) %>

results in a ‘Broken pipe’ error…

I’m using Ruby 1.8.6 with Rails 2.0.2 in NetBeans 6.0.1 as well. Is
there some other way I can troubleshoot or debug this?

Use the first one but remove the dot after the h

h.reagent.icon -> h reagent.icon

Ok, i had a burst of inspiration whilst on the ‘throne’ =P

I looked at the page source from the rendered version and saw that the
img tag didn’t include the /images/ prefix that i used in the
index.html.erb file.

The working code is:

Icon: <%=h @reagent.icon %>