Ruby on rails 尝试在rails管理中访问当前用户

Ruby on rails 尝试在rails管理中访问当前用户,ruby-on-rails,rails-admin,Ruby On Rails,Rails Admin,在rails admin config.model filterable选项中是否有访问当前用户的方法。我试过使用: bindings[:view]._current_user 但是绑定对我来说是零 下面是我一直在做的一段代码: field :user do filterable do #I want to access current user here bindings[:view]._current_user #bindings i

在rails admin config.model filterable选项中是否有访问当前用户的方法。我试过使用:

bindings[:view]._current_user
但是绑定对我来说是零

下面是我一直在做的一段代码:

field :user do
  filterable do                     #I want to access current user here
    bindings[:view]._current_user   #bindings is nil
  end

  pretty_value do
    bindings[:view]._current_user   #bindings is not nil
  end
end

我无法通过绑定方法访问它,所以我只是在我的应用程序控制器中创建了一个before过滤器,在那里调用一个方法,该方法通过类方法在我的用户模型中设置当前用户

因此,在我的代码片段中,我可以访问当前用户,如下所示:

...
filterable do
User.current
end
...
答案是这样的:

我无法通过绑定方法访问它,所以我只是在我的应用程序控制器中创建了一个before过滤器,在那里调用一个方法,该方法通过类方法在我的用户模型中设置当前用户

因此,在我的代码片段中,我可以访问当前用户,如下所示:

...
filterable do
User.current
end
...
答案是这样的: