# Passing a Record as a Parameter

**URL:** <https://www.ruby-forum.com/t/passing-a-record-as-a-parameter/56563>\
**Category:** Rails\
**Created:** [April 1, 2006, 5:26am UTC](https://www.ruby-forum.com/t/passing-a-record-as-a-parameter/56563 "2006-04-01T05:26:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggreaves](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bcef8e/32.png) [@ggreaves](https://www.ruby-forum.com/u/ggreaves)\
**Post date:** [April 1, 2006, 5:26am UTC](https://www.ruby-forum.com/t/passing-a-record-as-a-parameter/56563/1 "2006-04-01T05:26:43Z")

</div>

Consider the following code:

Snippet from my view…

\<% for cc in @classified\_categories %\>

\<%= link\_to cc.description, :controller =\>'classified\_ads', :action =\> 'list', :id =\>cc %\> \<% end %\>

… end snippet

the relevant bit is :id =\>cc

Snippet from my controller…

def list  
@classified\_category = ClassifiedCategory.new(params[:id])  
session[:classified\_category\_id] = @classified\_category.id  
session[:classified\_category\_name] = @classified\_category.name

@classified\_ad\_pages, @classified\_ads = paginate :classified\_ads,  
er\_page =\> 10

end

… end snippet

When I run it, I get the following error on the first line of the list  
action for the controller:

undefined method `stringify\_keys!’ for “1”:String

It works fine if I just pass the actual id of the record as a parameter  
(:id =\> cc.id) but I’d like to pass the entire record if that’s  
possible. Any suggestions?

-Greg

---

<div class="post-metadata">

**Author:** ![ggreaves](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bcef8e/32.png) [@ggreaves](https://www.ruby-forum.com/u/ggreaves)\
**Post date:** [April 1, 2006, 3:37pm UTC](https://www.ruby-forum.com/t/passing-a-record-as-a-parameter/56563/2 "2006-04-01T15:37:15Z")

</div>

I changed it so that instead of trying to pass the entire record, I just  
pass the id and then in the controller, do a

ClassifiedCategory.find(params[:id])

and it works ok. But this is unnecessary DB i/o if it can be avoided by  
just passing the record.

-Greg

Greg Greaves wrote:

> Consider the following code:
> 
> Snippet from my view…
> 
> \<% for cc in @classified\_categories %\>
> 
> \<%= link\_to cc.description, :controller =\>'classified\_ads', :action =\> 'list', :id =\>cc %\> \<% end %\>
> 
> … end snippet
> 
> the relevant bit is :id =\>cc
> 
> Snippet from my controller…
> 
> def list  
> @classified\_category = ClassifiedCategory.new(params[:id])  
> session[:classified\_category\_id] = @classified\_category.id  
> session[:classified\_category\_name] = @classified\_category.name
> 
> @classified\_ad\_pages, @classified\_ads = paginate :classified\_ads,  
> er\_page =\> 10
> 
> end
> 
> … end snippet
> 
> When I run it, I get the following error on the first line of the list  
> action for the controller:
> 
> undefined method `stringify\_keys!’ for “1”:String
> 
> It works fine if I just pass the actual id of the record as a parameter  
> (:id =\> cc.id) but I’d like to pass the entire record if that’s  
> possible. Any suggestions?
> 
> -Greg
