Is it possible to configure PaperTrail gem to ignore attributes globally?

[亡魂溺海] 提交于 2019-12-23 22:06:29

问题


The PaperTrail gem docs state that you can configure individual models to ignore some attributes -- This works great, but I want to skip all updated_at attributes (in every model). Is there a way to do this globally (in an initializer?). Something like PaperTrail.config.ignore = [:updated_at]

Related question: Is there a list of global configuration options for the PaperTrail gem?


回答1:


Currently (January 2017) there is no global model configuration in PaperTrail. You could do this with a global constant.

# config/initializers/global_constants.rb
GLOBAL_PT_IGNORE = [:updated_at]

# app/models/foo.rb
has_paper_trail(ignore: GLOBAL_PT_IGNORE + [:banana])

# app/models/bar.rb
has_paper_trail(ignore: GLOBAL_PT_IGNORE + [:kiwi, :mango])


来源:https://stackoverflow.com/questions/41548357/is-it-possible-to-configure-papertrail-gem-to-ignore-attributes-globally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!