paper_trail 2

一些‘选择’

你可以让paper_trail ‘忽略’ 一些改动,不记录它,比如 ‘忽略’ create :

class Article < ActiveRecord::Base
  has_paper_trail :on => [:update, :destroy] # 通过 on 选项
end

或者 ‘何时’ 才生成一个新版本 ‘version’

class Translation < ActiveRecord::Base
  # 通过 if 或 unless 选项
  has_paper_trail :if     => Proc.new { |t| t.language_code == 'US' },
                  :unless => Proc.new { |t| t.type == 'DRAFT'       }
end

再或者是 ‘忽略’ 一些不想 ‘跟踪’ 的属性:

class Article < ActiveRecord::Base
  has_paper_trail :ignore => [:title, :rating] # 通过 ignore
end

与上面的 ignore 相反,你可以‘只跟踪’自己 ‘指定’ 的属性

class Article < ActiveRecord::Base
  has_paper_trail :only => [:title] # 通过 only
end

从一开始就 ‘忽略’ 一些 属性(区别于上面的各个‘选项’)

class Article < ActiveRecord::Base
  has_paper_trail :skip => [:file_upload] # 用 skip
end

转载于:https://my.oschina.net/kelby/blog/193122

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值