Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1

Why is there no Application Model?


I know it sounds strange but I see that there's a application controller, helper and view but why no model for global/general use? I need a place to put scopes and methods that go across multiple models which wouldn't make sense if it was in one or the other. Can I do this now? Anybody have a way to handle this?

Thanks.


Solution

  • Either create a base model class, or a module. (Or both, I suppose.)

    The module can be mixed in to ActiveRecord::Base or individual models.

    You could also create class methods that include only specific scopes/methods, like:

    included_scopes :foo, :bar
    

    This can be helpful for documentation and readability so that functionality is explicit and obvious.

    Which (or which combination) makes sense depends on specifics, but there's a few ideas to kick around.