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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Workoidz if you are using rails >= 5.2 then use the following trick:
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 aSystemStackError (stack level too deep)
).