Image_tag problem

Hi

I am very new to RoR and am learning using the Agile Web D.
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 %>

If I replace <%= product.image_url %> with static text e.g.
/images/17.jpg the line of code works but I need to change the image
for each db record.

I have spent hours searching the web to help point me in the right
direction to no avail.

Thanks in advance for your help

Mark

The code snippt I specifically have a problem with is

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

This code looks a bit wrong… You don’t need to use the output tags
(<%= %>) in that string. In fact, it shouldn’t be a string at all in
this case. This should work fine:

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

Hope that helps,

Steve

On 9/28/06, Mark [email protected] wrote:

<%= 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 :slight_smile:

I imagine that if you looked at your source you would find something
like

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

Guys

Thank you for taking the time to reply, much appreciated.

Mark

On 28 September 2006 13:56, Mark wrote:

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

If I replace <%= product.image_url %> with static text e.g.
/images/17.jpg the line of code works but I need to change the image
for each db record.

The line should be as follows:

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

You see, you have already opened <%= %> braces, so another pair will not
be
evaluated. Also, there is no need for such complex transformations.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs