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 %> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 <a href="/add_to_cart/2"><img src="<%= product.image_url %>" /></a> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Guys Thank you for taking the time to reply, much appreciated. Mark --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---