# Find\_by\_user\_id\_and\_id question

**URL:** <https://www.ruby-forum.com/t/find-by-user-id-and-id-question/150923>\
**Category:** Rails\
**Created:** [October 14, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/find-by-user-id-and-id-question/150923 "2008-10-14T23:03:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [October 14, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/find-by-user-id-and-id-question/150923/1 "2008-10-14T23:03:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [October 14, 2008, 11:39pm UTC](https://www.ruby-forum.com/t/find-by-user-id-and-id-question/150923/2 "2008-10-14T23:39:19Z")

</div>

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
