I have the following code:
@countries = Country.find( :all, :order => 'name' )
@countries_with_tips = []
@countries.each do |country|
if country.tips.any?
@countries_with_tips.push( country )
end
end
I am getting each country that has at least one tip. A country has_many tips and a tip belongs_to a country
It works. But for Ruby it seems a little unelegant. Is there a better way?
Thanks in advance
Richard
1 Answer