Alex Rivera | Logout

Ruby Object#id warnings and Active Record

Asked 2009-03-03T23:42:58.157
9

We keep seeing warnings like the following when we run our specs:

Object#id will be deprecated; use Object#object_id

The code in question is accessing the id of an ActiveRecord model (which is an attribute on the table, obviously, rather than the object instance ID in the Ruby VM).

Does anyone know how to turn these particular warnings off or somehow avoid them?

Edit
Report

1 Answer

4

Your object is not actually an AR object, usually indicating that some data retrieval has failed (Table.find_by_name('nonexistent name') will return nil). If all you want to do is shut off the visible warnings, you can turn off whiny_nils in your config, otherwise do an is_a? test before trying to access the object's attributes and handle the failure case gracefully.

answered 2009-03-04T01:09:30.477

Your Answer