Created
May 21, 2014 22:43
-
-
Save dmitry/b94860e44516e417f6f4 to your computer and use it in GitHub Desktop.
Include paper_trail for all the models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.module_eval do | |
class << self | |
def inherited_with_paper_trail(subclass) | |
skip_models = %w(schema_migrations versions) | |
inherited_without_paper_trail(subclass) | |
table_name = subclass.table_name | |
if !skip_models.include?(table_name) && table_name.present? | |
subclass.send(:has_paper_trail) | |
end | |
end | |
alias_method_chain :inherited, :paper_trail | |
end | |
end |
@Workoidz if you are using rails >= 5.2 then use the following trick:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.inherited(subclass)
super
subclass.send(:has_paper_trail)
end
end
And skip_models
is used to ignore migrations and versions it self (as it doesn't required to make a versioning for those tables, and BTW versions will lead into a SystemStackError (stack level too deep)
).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is skip_models is for ..??