timpone
timpone

Reputation: 19929

warning message when running specs

I have the following:

  def toggle_follow_user tmp_id
    user=User.find(tmp_id)

but when I run specs I get the following warning:

DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `find`. Please pass the id of the object by calling `.id`. 

what is it trying to tell me and how do I fix it?

Upvotes: 1

Views: 3688

Answers (2)

PJSCopeland
PJSCopeland

Reputation: 3006

You're calling toggle_follow_user(a_user), not toggle_follow_user(a_users_id). Try this:

def toggle_follow_user(user)
  # just delete the line where you ::find the user, you're already passing it in

This will fix this particular issue - but check that it doesn't break anything else in your code!

If you are wanting to pass the user's id and find it inside the method, then look a call or two down your stack trace, because it's the whole object that's being passed in.

Upvotes: 0

ross_lafferty
ross_lafferty

Reputation: 121

Just for the sake of a test... I'm not sure what you are passing in that gets assigned to the tmp_id parameter, but I would surmise its an active record object, can you try this?

def toggle_follow_user tmp_id
  user=User.find(tmp_id.id)
end

If that works, its because whatever you were sending into toggle_follow_user was an entire active record "row" where Find wants an integer now (representing the ID... it used to pull it out natively, but that is going away it seems)

Upvotes: 4

Related Questions