Just need some more inside information... Sample Code from the AWDWR book. <%= link_to ( image_tag( product.image_url ), { :action => :add_to_cart, :id => product }, :method => :post, :confirm => "Are you sure?" ) %> Why is my ":id =>" reference using ''product'' and not ''product.id'' Is the :id symbol ''dual purpose'' and used as a key for an id param AND it also infers that the FIELD to ''get'' from the product object is named ''id''? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jun-08 14:24 UTC
Re: Passing :id param in link_to etc...
Hi -- On Fri, 8 Jun 2007, Jean Nibee wrote:> > > > Just need some more inside information... > > Sample Code from the AWDWR book. > > <%= link_to ( image_tag( product.image_url ), > { :action => :add_to_cart, :id => product }, > :method => :post, > :confirm => "Are you sure?" ) %> > > Why is my ":id =>" reference using ''product'' and not ''product.id'' > > Is the :id symbol ''dual purpose'' and used as a key for an id param AND > it also infers that the FIELD to ''get'' from the product object is named > ''id''?It uses the to_param method to get the value, so product ends up being product.to_param. By default, to_param returns the id, but you can override it if you wish: class Book < ActiveRecord::Base def to_param isbn end end for example. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---