Is it possible to parse an array of objects to select them by attribute? I have a situation where I need to display all objects of a model grouped by an attribute on the index page. What I had been doing in my controller is this...
#xx_controller.rb
@group1 = City.where(:population => 'big')
@group2 = City.where(:population => 'medium')
@group3 = City.where(:population => 'small')
But I'd prefer to do something like this in the controller...
@cities = City.all
And in my view something along the lines of a query, rather than prepackaged instance variables -
@cities.where....
Any thoughts?
@big_cities, @medium_cities, @small_citiesalso