在rails_admin paper_trail历史记录中显示用户的自定义标签 [英] Display custom label for User in rails_admin paper_trail history

查看:97
本文介绍了在rails_admin paper_trail历史记录中显示用户的自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我进入rails_admin中的paper_trail历史记录页面时,在用户"列(#<User:0x007f59a9...)中看到用户"对象.有没有一种方法可以配置为使用用户属性之一?我以为我可以使用object_label_method,但是我似乎没有任何运气.

When I go to a paper_trail history page in rails_admin, I see User objects in the User column (#<User:0x007f59a9...). Is there a way to configure this to use one of the User attributes? I thought I could use object_label_method but I don't seem to be having any luck.

更新:

我认为这纯粹是一个显示问题,但是paper_trail实际上是在版本表的whodunnit列中存储像#<User:0x007f59a9...这样的字符串,而不是ID.我已经覆盖了ApplicationController中的user_for_paper_trail,尽管这在我的前端应用程序中成功记录了具有用户ID的版本,但在rails_admin中却没有.根据此线程,rails_admin应该看到我的自定义方法,因为"RailsAdmin :: ApplicationController继承自您的:: ApplicationController".关于为什么发生这种情况以及如何获取paper_trail来存储用户ID的任何想法?

I thought this was purely a display issue but paper_trail is actually storing Strings like #<User:0x007f59a9... in the whodunnit column of the versions table rather than IDs. I have overridden user_for_paper_trail in ApplicationController and while this successfully logs versions with User IDs in my frontend app, it does not in rails_admin. According to this thread, rails_admin should see my custom method because "RailsAdmin::ApplicationController inherits from your ::ApplicationController". Any thoughts on why this is happening and how I can get paper_trail to store User IDs?

推荐答案

更多挖掘表明,这是某些宝石版本组合的已知问题. 此处是最近解决的rails_admin拉取请求. 此处是对该问题的更完整描述.

More digging revealed that this is a known problem with some combinations of versions of the gems. Here is a recent rails_admin pull request that addresses it. Here is a more complete description of the issue.

现在,我通过将以下代码放入config/initializers/rails_admin_user_for_paper_trail.rb来修补此漏洞:

For now, I'm monkey patching in the fix by putting the following code in config/initializers/rails_admin_user_for_paper_trail.rb:

RailsAdmin::ApplicationController.module_eval do
  def user_for_paper_trail
    _current_user.try(:id) || _current_user
  end
end

作为参考,我使用的是paper_trail 3.0.6,rails_admin 0.6.6和Rails 4.2.0.

For reference, I'm using paper_trail 3.0.6, rails_admin 0.6.6 and Rails 4.2.0.

这篇关于在rails_admin paper_trail历史记录中显示用户的自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆