Forum: Ruby on Rails show only notes for current user

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jag (Guest)
on 2007-07-31 00:49
(Received via mailing list)
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 %>
    <td><%=h note.send( %></td>
  <% end %>
    <td><%= link_to 'Show', :action => 'show', :id => note %></td>
    <td><%= link_to 'Edit', :action => 'edit', :id => note %></td>
    <td><%= link_to 'Destroy', { :action => 'destroy', :id =>
note }, :confirm => 'Are you sure?', :method => :post %></td>
<% end %>
Jeff E. (Guest)
on 2007-07-31 02:12
(Received via mailing list)
filter it in the controller:

def show
  @notes = Note.find(:all, :conditions => ["user_id = ?",]
Daniel -. (Guest)
on 2007-07-31 05:40
(Received via mailing list)
On 7/31/07, jemminger <removed_email_address@domain.invalid> wrote:
> filter it in the controller:
> def show
>   @notes = Note.find(:all, :conditions => ["user_id = ?",
> end

Or to use the has_many :notes association in the User model

def show
  @notes = @current_user.notes
Jeff E. (Guest)
on 2007-07-31 06:48
(Received via mailing list)
ah yes, even better!
This topic is locked and can not be replied to.