11175
(-- --)
1
This seems really simple but I can't seem to find an answer.
Say I have an array of Users which has a column called 'id'. I need an
array that holds just the ids. Right now I'm doing:
for user in users
ids << user.id
end
Is there a method to do this? Note that these objects aren't from my
database so I can't use find.
giorgio
(giorgio)
2
You should be able to use ids= users.collect {|u| u.id}
G.
u can also do like
@ids = User.find(:all, :select => 'id', :order=>'id')
11175
(-- --)
4
Say I have an array of Users which has a column called 'id'. I need an
array that holds just the ids.
ids = users.collect(&:id)
Samflores
(Samflores)
5
users.map { |user| user.id }
Samuel Flores
!#x000a