【问题标题】:Override rails activerecord touch method覆盖 rails activerecord touch 方法
【发布时间】:2014-02-10 21:24:50
【问题描述】:

有没有办法覆盖涉及相关模型时间戳的rails默认方法?

例子:

class User
  belongs_to :employer, touch: true
end

我想重写 touch 方法,而不是触摸雇主的时间戳应该做其他事情。

【问题讨论】:

    标签: ruby-on-rails-3 activerecord callback


    【解决方案1】:

    你应该能够做这样的事情

    class User
      ...
      def touch
    
        # your fancy stuff goes here
    
        super
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2011-02-22
      • 2015-07-30
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-17
      相关资源
      最近更新 更多