本文介绍了是否可以将PaperTrail gem配置为全局忽略属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PaperTrail gem文档指出,您可以将各个模型配置为忽略某些属性-效果很好,但我想跳过所有updated_at属性(在每个模型中).有没有一种方法可以全局(在初始化器中)?类似于PaperTrail.config.ignore = [:updated_at]

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]

推荐答案

当前(2017年1月)在PaperTrail中没有全局模型配置.您可以使用全局常量来做到这一点.

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])

这篇关于是否可以将PaperTrail gem配置为全局忽略属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 14:33