在表版本中,我创建了新列'localip'。 在视图中,我有一个隐藏字段,可通过JS进行赋值:
<%= f.hidden_field :localIP, :value => params[:localIP] %>
如果我正确理解paper_trail首先被调用,那么我将其放入控制器:
prepend_before_action :set_localip, only: :update
def info_for_paper_trail
{
:ip => request.remote_ip,
:agent => request.user_agent,
:localip => @localip
}
end
private
def set_localip
@localip = params[:localIP]
end
但在更新期间:未通过localip:
PaperTrail::Version Create (0.3ms) INSERT INTO "versions" ("item_type", "item_id", "event", "whodunnit", "object", "created_at", "object_changes", "ip", "agent") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
有人知道如何传递这种价值吗?
答案 0 :(得分:0)
已解决:
在控制器中:
Reclaim Policy
/config/initializers/paper_trail.rb
prepend_before_action :set_localip, only: :update
before_action :set_paper_trail_whodunnit, if: :user_signed_in?
def info_for_paper_trail
{
:ip => request.remote_ip,
:agent => request.user_agent,
:localip => @localip
}
end#
private
def set_localip
@localip = params.require(:commission)[:localIP]
end