I have a user.rb model (this is ActiveRecord :: Base, not sure if it is relevant to the discussion)
In some views, I am comparing two users with:
<% if current_user == user %>
The result is undefined (sometimes the result is true, and sometimes false), and I'm not sure why.
If I switch it to
<% if current_user.id == user.id %>
It works as expected. But then I need to handle the case where the user may be null.
My question is: what is going on here?
Why does user1 == user2 not work here?
Should I override == or
Should I use an alternative method like equal ?, === or eql?
Shouldn't user.rb be an ActiveRecord :: Base mean == value by default already comparing id fields?
source
share