How to get the list of users' id


I have a question that how to take a list of user on user table

def show_pic

@id = User.find(:all, :select => ‘’)
@id.each do |i|
@pic = ActiveRecord::Base.connection.select_value(
select picture
from albums a
inner join Users u
on =
where = i )

please give me some advices…

THanls you so much

On 13 June 2011 18:33, Yennie [email protected] wrote:

please give me some advices…

Assuming your users have a “has_many :pictures” relationship:

@pictures =

Or if your Users have many Albums, and Albums have many Pictures:

@pictures =

(can probably use .inject to make that smaller, but you can look that
up in the api docs)

then you can iterate @pictures however you want in your views.

but… hang on…

Aren’t you just getting a list of all the Pictures? Why not use

Sorry, I mean get the list of user id …
cuz my query depends on … so i want to have a list which is
to go through
the album…

I don’t see what you are trying to achieve here. Surely you just have a
list of Users:


Given Users has_many :albums, you could handle this in the view along
with pictures. To limit the number of requests to the database, make
sure to include the associations:

User.all.include :albums

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