Let's say I want to define some methods and helpers that will be available in all my models ActiveRecord
.
A little research tells me that there are two common options
Module
Define a module
module MyModule
def foo
end
end
Include it in the model when you need it
class User < ActiveRecord::Base
include MyModule
before_save :foo
end
Inheritance
Define a base class
class BaseModel < ActiveRecord::Base
self.abstract_class = true
def foo
end
end
Make all models inherited from it
class User < BaseModel
include MyModule
before_save :foo
end
What are the pros and cons for each - are there any special advantages to this? Is there one that was more seen as a "Rails way"?
Thank!
source
share