Object#id being deprecated - Rails 1.1

Hi

Think this is probably straightforward, but I don’t know enough about
rails to work it out, so was wondering if anyone can help

I keep on running into this error when I’m deploying my app:

“FastCGI: server “…/public_html/public/dispatch.fcgi” stderr:
…/config/…/app/views/items/_side_share.rhtml:8: warning: Object#id
will be deprecated; use Object#object_id”

l.8 is <%= link_to ‘Bookmark this’, :action => ‘bookmark’, :id =>
@item.id %>

From http://corelib.rubyonrails.org/classes/Object.html#M001093 etc, I
can see that the @item.id is throwing the error, and that @item.item_id
just gives me a no method error.

Any help would be great, if people have time.

Thanks

Piers

Piers Y. <piers.young@…> writes:

From http://corelib.rubyonrails.org/classes/Object.html#M001093 etc, I
can see that the item.id is throwing the error, and that
item.item_id
just gives me a no method error.

Hmm… I know it sounds obvious, but have you tried @item.object_id?

– Pazu

Piers Y. wrote:

“FastCGI: server “…/public_html/public/dispatch.fcgi” stderr:
…/config/…/app/views/items/_side_share.rhtml:8: warning: Object#id
will be deprecated; use Object#object_id”

l.8 is <%= link_to ‘Bookmark this’, :action => ‘bookmark’, :id =>
@item.id %>
@item’s probably nil. If it was an AR object, it would respond to id()
without throwing an error. nil, being an object, responds to id(), but
with exactly that warning message.

Hmm… I know it sounds obvious, but have you tried @item.object_id?

– Pazu

Thanks Pazu - worked a treat.
Feeling very silly

Piers

On Mar 21, 2006, at 5:52 AM, Piers wrote:

Hmm… I know it sounds obvious, but have you tried @item.object_id?

– Pazu

Thanks Pazu - worked a treat.
Feeling very silly

I’m finding it hard to believe that’s the solution you’re looking for.


– Tom M.

I’ve come across this same problem before, and just as Alex suggested,
it was because my active record object was nil. As well as obviously
ensuring that it isn’t nil, you could try replying you link with the
following:

<%= link_to ‘Bookmark this’, :action => ‘bookmark’, :id => @item %>

Note that I’m just using @item instead of @item.id. In this case,
link_to knows to try and extract the id from @item, and it does it by
called @item.to_param, which is an active record method which defaults
to returning the id. From memory, this gives a much more graceful result
if the id is null.

regards,

Craig