if @result.exists?
if @result.user_id != current_user.id #<---HERE!!!!
...
I need to check if the searched 'Item' does not have the same 'user_id'
with the current logged-in user.
So I need to get the 'user_id' field of @result.
But certainly, putting '@result.user_id' gives an error.
How was I supposed to get 'user_id' from the @result object?
What's the status of the @result object? Is it nil? Does it have any
value? What do you get if you inspect it or print it? What's the exact
error you get?
Looking at ruby docs, this is the explanation for the method - Evaluates
to true if this resource is not new? and is found on the remote service.
Using this method, you can check for resources that may have been
deleted between the object’s instantiation and actions on it.
The reason it did not work originally is that @result is not a single
record, it is all the records that match the where clause. In
practice it may be only one but it will still be returned in,
effectively, an array. Hence the need to use .first to get the first
one.