Forum: Ruby on Rails Simple question about :list method in scaffolds

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.
Elan (Guest)
on 2006-01-26 21:58
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
Kevin O. (Guest)
on 2006-01-26 22:11
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,
>
> -elan

Assuming 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
This topic is locked and can not be replied to.