# Show only notes for current user

**URL:** <https://www.ruby-forum.com/t/show-only-notes-for-current-user/110786>\
**Category:** Rails\
**Created:** [July 30, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/show-only-notes-for-current-user/110786 "2007-07-30T22:49:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jag](https://www.ruby-forum.com/u/jag)\
**Post date:** [July 30, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/show-only-notes-for-current-user/110786/1 "2007-07-30T22:49:56Z")

</div>

hi, i’ve written an app but failing on one pivotal part,

i have a user model built, and a notes model built

now, once the user navigates to the notes view they can create notes  
and they will only be available to that user.

i’ve got it saving the user\_id to the note record, but not filtering  
out only notes for that current user.

any ideas?

sample code

\<% for note in @notes %\>

 \<% for column in Note.content\_columns %\> \<%=h note.send(column.name) %\> \<% end %\> \<%= link\_to 'Show', :action =\> 'show', :id =\> note %\> \<%= link\_to 'Edit', :action =\> 'edit', :id =\> note %\> \<%= link\_to 'Destroy', { :action =\> 'destroy', :id =\> note }, :confirm =\> 'Are you sure?', :method =\> :post %\> \<% end %\>

---

<div class="post-metadata">

**Author:** ![jag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jag](https://www.ruby-forum.com/u/jag)\
**Post date:** [July 31, 2007, 12:12am UTC](https://www.ruby-forum.com/t/show-only-notes-for-current-user/110786/2 "2007-07-31T00:12:06Z")

</div>

filter it in the controller:

def show  
@notes = Note.find(:all, :conditions =\> [“user\_id = ?”,  
@current\_user.id]  
end

---

<div class="post-metadata">

**Author:** ![jag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jag](https://www.ruby-forum.com/u/jag)\
**Post date:** [July 31, 2007, 3:40am UTC](https://www.ruby-forum.com/t/show-only-notes-for-current-user/110786/3 "2007-07-31T03:40:19Z")

</div>

On 7/31/07, jemminger [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> filter it in the controller:
> 
> def show  
> @notes = Note.find(:all, :conditions =\> [“user\_id = ?”,  
> @current\_user.id]  
> end

Or to use the has\_many :notes association in the User model

def show  
@notes = @current\_user.notes  
end

---

<div class="post-metadata">

**Author:** ![jag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jag](https://www.ruby-forum.com/u/jag)\
**Post date:** [July 31, 2007, 4:48am UTC](https://www.ruby-forum.com/t/show-only-notes-for-current-user/110786/4 "2007-07-31T04:48:25Z")

</div>

ah yes, even better!
