The automatically generated scaffolds made code like this: def list @address_pages, @addresses = paginate :addresses, :per_page => 10 end which was fine, but I only want to return the logged-in user''s addresses. So I changed it to: def list @address_pages, @addresses = paginate :addresses, :per_page => 10, :conditions => [''user_id = ?'', @session[''user''].id] end Is this the right way to do it, or am I missing something? Thanks, -elan -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jan-26 20:11 UTC
[Rails] Re: Simple question about :list method in scaffolds
Elan wrote:> The automatically generated scaffolds made code like this: > > def list > @address_pages, @addresses = paginate :addresses, :per_page => 10 > end > > which was fine, but I only want to return the logged-in user''s > addresses. So I changed it to: > > def list > @address_pages, @addresses = paginate :addresses, :per_page => 10, > :conditions => [''user_id = ?'', @session[''user''].id] > end > > Is this the right way to do it, or am I missing something? > > Thanks, > > -elanAssuming your table is set up with a user_id column for the addresses, it should work fine. Just make sure the user_id column gets populated when records are created. _Kevin -- Posted via http://www.ruby-forum.com/.