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.
Hi –
On Fri, 8 Jun 2007, Jean N. wrote:
: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 (Ruby for Rails)
(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)