- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已将 papertrail 设置为仅记录包含 whodunnit 值的更改/当管理员通过在我的模型中使用以下条件进行更改时:
has_paper_trail if: proc { |model| PaperTrail.request.whodunnit.present? }
但是我注意到仍然有相当数量的记录被存储为空的 whodunnit 值。从查看记录来看,这些似乎主要是“更新”操作,由于某种原因,所有的对象都发生了变化。我不确定为什么该值是空的,或者考虑到上述条件它会如何被保存。
def user_for_paper_trail
request.env['warden']&.user(:admin)&.id
end
有没有人遇到过类似的行为?
最佳答案
添加 source_location
和 command
您的 Papertrail 版本表中的字段将帮助您:
nil
的命令谁不知道改变。 source_location
和
command
字段到您的版本表:
class AddSourceLocationAndCommandToVersions < ActiveRecord::Migration
def change
add_column :versions, :source_location, :text
add_column :versions, :command, :text
end
end
我在
papertrail.rb
中有以下设置.我正在使用
JSON serializer
但是这些更改可能适用于普通的序列化程序。
serializer
后面的代码声明是您感兴趣的内容:
require "paper_trail/frameworks/rails"
require "paper_trail"
# the following line is required for PaperTrail >= 4.0.0 with Rails
PaperTrail::Rails::Engine.eager_load!
PaperTrail.config.enabled = true
PaperTrail.serializer = PaperTrail::Serializers::JSON
# Store some metadata about where the change came from, even for rake tasks, etc.
# See: https://github.com/paper-trail-gem/paper_trail/wiki/Setting-whodunnit-in-the-rails-console
def PaperTrail.set_global_metadata
request.controller_info ||= {}
request.controller_info[:command] ||= "#{File.basename($PROGRAM_NAME)} #{ARGV.join ' '} (#{$PID})"
request.controller_info[:source_location] = caller.find { |line|
line.starts_with? Rails.root.to_s and
!line.starts_with? __FILE__
}
end
# Defer evaluation in case we're using spring loader (otherwise it would be something like "spring app | app | started 13 secs ago | development")
# There's no way to set up deferred evaluation of PaperTrail.request.controller_info from here like
# we can with whodunnit, so abuse that property of PaperTrail.request.whodunnit to set other
# metadata. Reserve the whodunnit field for storing the actual name or id of the human who made the
# change.
PaperTrail.request.whodunnit = ->() {
PaperTrail.set_global_metadata
if Rails.const_defined?("Console") || $rails_rake_task
"#{`whoami`.strip}: console"
else
"#{`whoami`.strip}: #{File.basename($PROGRAM_NAME)} #{ARGV.join ' '}"
end
}
Rails.application.configure do
console do
PaperTrail.request.controller_info = { command: "rails console" }
PaperTrail.request.whodunnit = ->() {
PaperTrail.set_global_metadata
@paper_trail_whodunnit ||= (
if Rails.const_defined?("Console") || $rails_rake_task
"#{`whoami`.strip}: console"
else
"#{`whoami`.strip}: #{File.basename($PROGRAM_NAME)} #{ARGV.join ' '}"
end
)
}
end
end
whodunnit
如果您不希望它为空,则将其值指定为特定的东西。例如。在我的种子文件中,我执行以下操作:
class SeedCreator
def initialize
PaperTrail.request.whodunnit = ->() {
PaperTrail.set_global_metadata # save source_location & command
"seed" # set whodunnit value to "seed"
}
create_campaign
create_users
# more seeding of models....
end
end
除了提高 Papertrail 表的质量(知道哪个命令触发了记录更新)之外,此配置还应帮助您确定幻像
whodunnits
的位置。正在被拯救。
关于ruby-on-rails - 纸迹 : records with nil whodunnit values and object_changes in logs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65563549/
在生产中使用 paper_trail 一段时间后,我实现了 object_changes。有没有办法为在添加此字段之前创建的对象填充 object_changes 字段?我想应该有。 paper_tr
我正在使用 Rails 3.1 的书面记录,并且希望了解模型之间的差异。看起来这是通过将 object_changes 作为文本列添加到版本来支持的。我已经这样做了,但更改集没有被保存。还需要执行其他
这与#837有些相关因为我的模型上有一个大数据列,但是我认为与该问题中提议的相反,我可能会更好地为我服务 - 即维护对象列而不是 object_changes 列。 我们一直在没有 versions.
我们刚刚开始使用 PaperTrail gem并且注意到版本表中 75% 的记录为 object_changes 为零。柱子。知道为什么会发生这种情况以及我们如何阻止它吗? 使用 Rails 5.1
我已将 papertrail 设置为仅记录包含 whodunnit 值的更改/当管理员通过在我的模型中使用以下条件进行更改时: has_paper_trail if: proc { |model| P
我是一名优秀的程序员,十分优秀!