Querying with parameters

First of all, thanks for the awesome documentation. It’s been a cornerstone for using Rails.

One thing has been bothering me about the rails guide though. According to the guide, if you have a scope that takes arguments, you’re suppose to use a class method instead (http://guides.rubyonrails.org/active_record_querying.html#passing-in-arguments). I understand the rationale but I still am leery of using this pattern for several reasons:

  1. It can be hard sometimes to tell if a class method is returning a scoped relation or not.
  2. It’s expected that scopes work on scopes/associations/etc but with class methods, it feels like there’s a bit of magic going on. Like how does ActiveRecord know whether a class method is a scope or not? And so on.
  3. When you use this pattern, you don’t know if you’re looking for a scope or a class method. For example, the “admin” in User.admin might either be a scope or a class method. You don’t know.
  4. I think this made a lot more sense with Ruby 1.8. Now with 1.8 at its end of life, I think scopes are just as effective since you can specify default arguments with lambdas, use the splat for lambdas, etc.
    I think the documentation would be better if in the very least it just outlined both methods and did not comment on which was preferred. Thanks.

Hi David,

Replies are inline. (gmail has buggered your numbering, sorry!)

Thanks for the response. Maybe I will take a stab at adding an example with a 1.9 lambda to the Rails Guide.