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.
6b46f4eed76df33a3ffacf87bc9f1079?d=identicon&s=25 vimal (Guest)
on 2009-03-05 10: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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 10:45
(Received via mailing list)
On Mar 5, 9:26 am, vimal <cool.vimalsm...@gmail.com> wrote:

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

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

Fred
6b46f4eed76df33a3ffacf87bc9f1079?d=identicon&s=25 vimal (Guest)
on 2009-03-05 11: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.