Find_by_user_id_and_id question

Hi,

I wondering about the next:

The book Advance Rails states that using

def show
@message = Message.find_by_user_id_and_id(current_user.id,
params[:id])
end

Should return RecordNotFound if the user that tries to view a message is
not the one that created it.

But what I get is:

You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.sender_name

And that is fine since it gets to the view and the @message used there
is nil.

But the find_by_user_id_and_id was not returning RecordNotFound. Which
is something I could use a common error page for.

I’m I missing something?

Thanks.

On 14 Oct 2008, at 22:03, Pod C. wrote:

end

Should return RecordNotFound if the user that tries to view a
message is
not the one that created it.

That’s just not what find_by … does. It behaves more like find :first

Fred