Forum: Ruby on Rails How do I only show items that belong to a certain user?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5e197c8f7663929dd8c2d978f0f0d0eb?d=identicon&s=25 David Smit (dawie)
on 2008-10-19 23:06
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.
A39970d780c506b26e9a8b71eda13df2?d=identicon&s=25 Walter McGinnis (Guest)
on 2008-10-19 23:56
(Received via mailing list)
@current_user.documents rather Document.find(:all).
Cheers,
Walter McGinnis
A39970d780c506b26e9a8b71eda13df2?d=identicon&s=25 Walter McGinnis (Guest)
on 2008-10-19 23:57
(Received via mailing list)
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
Fac81a9d95c81d817a2debb6f717f3ac?d=identicon&s=25 Sazima (Guest)
on 2008-10-20 14:44
(Received via mailing list)
@user.documents

Cheers, Sazima

On Oct 19, 7:06 pm, David Smit <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.