Forum: Ruby on Rails Retrieving all values of the column from the table

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.
vimal (Guest)
on 2009-03-05 11:27
(Received via mailing list)
Hi,

I have a function in my model like
-----------------------------------------
class Pattern
  def self.get_all(field)
    @patterns = Pattern.find(:all)
    @patterns.collect do |pp|
      pp.field
    end
  end
end
-----------------------------------------
so that whatever field i give to the function,
it returns all the column values in an Array

I dont know whether i am doing it right or not
Any suggestions

Thanx,
Vimal Das
Frederick C. (Guest)
on 2009-03-05 11:45
(Received via mailing list)
On Mar 5, 9:26 am, vimal <removed_email_address@domain.invalid> wrote:

> I dont know whether i am doing it right or not

Well, have you tried it ? (look up the send method)

Fred
vimal (Guest)
on 2009-03-05 12:40
(Received via mailing list)
I tried it Fred,but it didn't work

Instead this did the job for me

class Pattern
  def self.get_all(field)
    @patterns = Pattern.find(:all)
    @patterns.collect do |pp|
      pp[field]
    end
  end
end

Regards,
Vimal Das
This topic is locked and can not be replied to.