[Rails] ActiveRecord array/collection manage

2011-06-05 Thread danimashu
Hello, I have a model like this: class Car ActiveRecord::Base def color(c) where(color = ?,c) end end Suppose that I want to show the red and blue cars. I could do something like this: @cars = Car.color('blue') + Car.color('red') The problem I'm finding is that now, @cars is an array

Re: [Rails] ActiveRecord array/collection manage

2011-06-05 Thread Valery Kvon
Pagination obviously doesn't works on Array, but ActiveRecord::Relation set. You have to rewrite your color selector using 'standard de facto' approach: class Car ActiveRecord::Base scope :colored, lambda { |color| where(:color = color) } end Then just call: Car.colored(%w{red blue}).page