# How do I only show items that belong to a certain user?

**URL:** <https://www.ruby-forum.com/t/how-do-i-only-show-items-that-belong-to-a-certain-user/151289>\
**Category:** Rails\
**Created:** [October 19, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/how-do-i-only-show-items-that-belong-to-a-certain-user/151289 "2008-10-19T23:06:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 19, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/how-do-i-only-show-items-that-belong-to-a-certain-user/151289/1 "2008-10-19T23:06:27Z")

</div>

I have a web application with users and their documents. Each user can  
have many documents:

user.rb:

has\_many :documents

document.rb:

belongs\_to :user

document\_controller.rb:

def index  
@documents = Document.find(:all)  
end

I am using the restful\_authentication plugin. Here is my question: How  
do I get the controller to only show documents that belongs to each  
user? Right now it shows all the documents for all the users.

I am using the latest version of Rails.

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 19, 2008, 11:56pm UTC](https://www.ruby-forum.com/t/how-do-i-only-show-items-that-belong-to-a-certain-user/151289/2 "2008-10-19T23:56:38Z")

</div>

@current\_user.documents rather Document.find(:all).  
Cheers,  
Walter McGinnis

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 19, 2008, 11:57pm UTC](https://www.ruby-forum.com/t/how-do-i-only-show-items-that-belong-to-a-certain-user/151289/3 "2008-10-19T23:57:49Z")

</div>

Oh, I should say that I’m not sure what the actual user variable is when  
using restful\_authentication, but that is the concept you want to go  
for.  
Cheers,  
Walter

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [October 20, 2008, 2:44pm UTC](https://www.ruby-forum.com/t/how-do-i-only-show-items-that-belong-to-a-certain-user/151289/4 "2008-10-20T14:44:48Z")

</div>

@user.documents

Cheers, Sazima

On Oct 19, 7:06 pm, David S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
