Named Scopes Are Dead
Lots of people love using named scopes in Rails 2. However, in Rails 3 they’re not only more or less obsolete but can also hinder productiveness in teams by being update blockers. Read about the reasons and alternatives in the railway blog.
Comments
Fixed: http://github.com/rails/rails/commit/181c414baa877d748671d03fb09499c10f81ec02 https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4142-arel-methods-in-scope-cause-issues-with-non-existent-tables The workaround looks messy to me.
When I first gave AR 3 a go, I wondered if you could just use class methods for the same benefits as scopes considering the lazy evaluation. Glad someone else actually tried it and confirms it works ;-) That class << self stuff is a big gangly though.. def self.published reads somewhat nicer.
That class « self stuff is a big gangly though.. def self.published reads somewhat nicer.
I agree with you on this one but I have seen several posts which suggest that this is not the best practice… (I have yet to understand why).
Peter: I prefer class « self simply to keep things more organized – all class methods in one place (alright, alright, meta class’ instance methods ;-)). And they’re easier to grep for – it’s always def whatever, no difference between instance and class methods.
Nothing wrong with a preference, of course, but it’s still more verbose (and if used in anger leads to situations where you’re not entirely sure if a method is a class or instance method, unless you go looking for the associated class definition).
Post a comment