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 and I could not do something like that: @cars.page(params[:page]).per(10) @cars.order( ..... ) or any method ActiveRecord implements. The question is: ¿How can I manage ActiveRecord array/collection for do: + - | &? Thanks very much. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 ... etc On 05.06.2011, at 20:11, danimashu wrote:> Hello, I have a model like this: > > class Car < ActiveRecord::Base > def color(c) > where("color = ?",c) > end > end-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Should it be: class Car < ActiveRecord::Base def self.color(c) ... end end Allan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/QWlTM2tvR1IzSU1K. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Great Valery! I''ve solved it. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.