我的一个 AR 模型中有以下代码片段:
after_update :cache_bust
模型中的 cache_bust
方法接受一个参数( bool 值),默认将其自身的值设置为 false
。
如何从上面定义的 ActiveRecord 回调中将 true
传递给模型中的这个方法?
例如:after_update :cache_bust(true)
不起作用,因为它是一个符号,我如何将 true
传递给方法的参数?
最佳答案
There are four types of callbacks accepted by the callback macros: Method references (symbol), callback objects, inline methods (using a proc), and inline eval methods (using a string).
试试这个?
after_update -> { cache_bust(true) }
关于ruby-on-rails - Rails 将参数/参数传递给 ActiveRecord 回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30221810/