Simple question about :list method in scaffolds

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

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs