Show only notes for current user


#1

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 %>

#2

filter it in the controller:

def show
@notes = Note.find(:all, :conditions => [“user_id = ?”,
@current_user.id]
end


#3

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 = ?”,
@current_user.id]
end

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

def show
@notes = @current_user.notes
end


#4

ah yes, even better!