0

I know I can make a module that defines a scope and include this module in a model, following, for example, this question's discussion.

But say I have 100 models, all of which have created_at fields. I want to have a scope reading from created_at, but I do not want to manually include the module in all the models. I want to define a scope globally for all models.

Seeing how all models inherit from ActiveRecord::Base, I keep looking for ways to define a scope there, but my efforts with using concerns end up with errors.

ActiveRecord::ActiveRecordError: ActiveRecord::Base doesn't belong in a hierarchy descending from ActiveRecord
Community
  • 1
  • 1
Epigene
  • 3,634
  • 1
  • 26
  • 31
  • That's not a good idea. You should not modify ActiveRecord::Base or you will increase the risk of conflicts. The right approach is to include the module in your models. – Simone Carletti Sep 21 '15 at 16:56
  • The `scoped` portion in that other answer was throwing me off, since it is deprecated in Rails4. Put an updated answer there. – Epigene Sep 22 '15 at 06:53

0 Answers0