caseyli/capo — comment on commit 7e650fb7c4833fdeed4b4732f0076c24e20f600b
File: app/controllers/open_mics_controller.rb line 50
By jduff:

AREL makes getting a list of objects based on conditions really easy. I think the main chunk of this action could be simplified to:

``` ruby
@open_mics = OpenMic.scoped # this is basically 'all' but can be chained with other active relation calls, like where etc.
@open_mics = @open_mics.published unless admin?

if params[:filter_city_prov_state],present?
city = params[:filter_city_prov_state].split(',').first # I might actually pull this out in a `before_filter` instead
prov_state = params[:filter_city_prov_state].split(',').last.strip
@open_mics = @open_mics.where(:city => city, :prov_state => prov_state))
end
```

The awesome part about AREL is until you make a call that actually needs the object (each, etc) you can keep calling methods on the relation.