# Passing :id param in link\_to etc

**URL:** <https://www.ruby-forum.com/t/passing-id-param-in-link-to-etc/106326>\
**Category:** Rails\
**Created:** [June 8, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/passing-id-param-in-link-to-etc/106326 "2007-06-08T16:18:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [June 8, 2007, 4:18pm UTC](https://www.ruby-forum.com/t/passing-id-param-in-link-to-etc/106326/1 "2007-06-08T16:18:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeannibee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@jeannibee](https://www.ruby-forum.com/u/jeannibee)\
**Post date:** [June 8, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/passing-id-param-in-link-to-etc/106326/2 "2007-06-08T16:25:36Z")

</div>

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](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](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](http://www.rubypal.com))
