无法访问 AcitveAdmin 表单定义中的设备 current_admin_user
我需要仅向特定用户显示 ActiveAdmin 表单中的某些表单字段。 但是,当我尝试使用此代码检查用户状态时:
ActiveAdmin.register Store do
# ...
form do |f|
f.inputs "Basic" do
if current_admin_user.super_admin?
f.input :admin_user
end
# ...
end
end
end
我发现
undefined local variable or method `current_admin_user' for #<ActiveAdmin::DSL:0xdb8e798>
CanCan 方法在 ActiveAdmin 表单定义中也不起作用。
一般来说,我的问题是:如何根据当前用户类型管理管理界面显示? 特别是,如何从 ActiveAdmin 定义中获取当前的设备用户对象?
I need to display some form fields in ActiveAdmin form only to specific users.
But when I try to check user status with this code:
ActiveAdmin.register Store do
# ...
form do |f|
f.inputs "Basic" do
if current_admin_user.super_admin?
f.input :admin_user
end
# ...
end
end
end
I get
undefined local variable or method `current_admin_user' for #<ActiveAdmin::DSL:0xdb8e798>
CanCan methods also don't work in the ActiveAdmin form definition.
Generally my question is: how can I manage admin interface display, based on current user type?
Particularly, how can I get current devise user object from within ActiveAdmin definitions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个范围问题。您可以尝试使用 f.template 对象访问辅助方法,如下所示:
祝您好运。
It is a matter of scope. You could try accessing the helper method using the f.template object like so:
Good luck.
我找到了解决此问题的方法。在 /app/admin/stores.rb: 中
,然后在 /app/views/admin/stores/_form.html.haml: 中:
这一点都不方便,但可以。
I've found a workaround for this issue. In /app/admin/stores.rb:
and then in /app/views/admin/stores/_form.html.haml:
It's not convenient at all, but works.
我知道这个线程有点旧,但我刚刚找到了一个很好的小解决方案。我没有使用 devise,而是使用 Twitter API 来登录我的用户
在
active_admin.rb
中,查找config.current_user_method
并将默认值更改为 < code>current_user fromcurrent_admin_user
config.current_user_method = :current_user
同时将
logout_link_path
更改为您的路由包含as: :destroy_user_session
I know this thread is a little old but I just found a nice little fix for this. I'm not using devise, I'm using the Twitter API for logging in my users
In
active_admin.rb
, look forconfig.current_user_method
and change the default value tocurrent_user
fromcurrent_admin_user
config.current_user_method = :current_user
Also change the
logout_link_path
to in your routes to includeas: :destroy_user_session