:subclasses Replacement in Rails 3
Right now I have:
@models = ActiveRecord::Base.send(:subclasses)
开发者_高级运维
But I get this in the log:
DEPRECATION WARNING: subclasses is deprecated and will be removed from Rails 3.0 (use descendants instead). (called from send at /Users/*******/m3p0/app/controllers/roles_controller.rb:50)
What should I replace :subclasses
with?
It is in the warning, it says use descendants instead.
ActiveRecord::Base.send(:descendants)
Also, these methods are publicly available so you don't need to use the .send syntax, you can call it explicitly.
ActiveRecord::Base.descendants
Here is the output from one of my apps:
ruby-1.9.2-p180 :001 > ActiveRecord::Base.subclasses
=> [Achievement(id: integer...
ruby-1.9.2-p180 :003 > ActiveRecord::Base.descendants
=> [Achievement(id: integer...
精彩评论