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

<p>user.rb: </p>

<pre><code>has_many :documents
</code></pre>

<p>document.rb:</p>

<pre><code>belongs_to :user
</code></pre>

<p>document_controller.rb:</p>

<pre><code>def index
    @documents = Document.find(:all)
end
</code></pre>

<p>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.</p>

<p>I am using the latest version of Rails.</p>

You set a relationship in your User class to your Document class. This will automatically add a method to your User objects that returns a list of all documents related to a particular user:
```
```
def index
  @documents = @current_user.documents
end
```
```
See the
documentation
for other automatically added methods.