Re: Image_tag problem

Daniel N
Thu, 28 Sep 2006 10:21:04 -0000

On 9/28/06, Mark <mhelsby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
>
> Hi
>
> I am very new to RoR and am learning using the Agile Web Development
> with Rails referece. I am slowly creating the Depot application and
> have a problem setting up an image to act as a hyper link.
>
> The code snippt I specifically have a problem with is
>
> <%= link_to image_tag(''<%= product.image_url
%>''),   :action =>
> :add_to_cart, :id => product  %>


Inside the <%=  and %> you are using ruby code.  What you have effectively
done here is tried to firstly put a string literal into the image_tag
method.  The you''ve used an erb escape inside ruby script.   The good
news
is you don''t need to do this :)

I imagine that if you looked at your source you would find something like
<img src="<%=
product.image_url %>" />

Instead use
<%= link_to image_tag( product.image_url ), :action => :add_to_cart, :id
=>
product %>

That should resolve the image url to the product objects image_url method.

Hope that helps a bit.

Cheers
Dan