Topic: Having model return one field as a list

I have a model which has a table with a field called city.
I want the model to be able to return a list of all cities, I have code which works in the console but when I try and transfer this to my model I get a string returned: "#Provider:0x3b6a940".

# Return array of all cities
def self.cities
  find(:all).uniq.collect { |p| p.city }
end

I can do this in the console quite easily:

Provider.find(:all).uniq.collect { |p| provider.city } => ['city1'], ['city2'], ['city3']

By the way I put self before the method name so that it is a class method and can be used like this: Provider.cities

Many thanks, AFM

Last edited by afm (2006-07-11 10:18:15)

Re: Having model return one field as a list

I just refresh and this started working, strange !