Rails 3 ActiveAdmin。如何为具有非管理员角色的用户禁用仪表板?
这是我查看用户角色的方式: current_admin_user.role
我正在使用 CanCan
如何
- 隐藏仪表板按钮
- 限制对仪表板的访问,以防用户发现其 url
- 我已经尝试过这个但不起作用。
dashboard_controller.rb
if current_admin_user.role == 'customer'
redirect_to shipments_path
end
我在 admin/dashboards.rb 中尝试了此操作
controller do
def scoped_collection
if current_admin_user.role == 'customer'
redirect_to shipments_path
end
end
end
,但产生错误 undefined method 'controller' for ActiveAdmin::Dashboards:Module (NoMethodError)
This is how I can see user's role: current_admin_user.role
I'm using CanCan
How can I
- Hide the Dashboard button
- Restrict access to the Dashboard in case the user finds out it's url
-
I have tried this but doesn't work.
dashboard_controller.rb
if current_admin_user.role == 'customer'
redirect_to shipments_path
end
I tried this in admin/dashboards.rb
controller do
def scoped_collection
if current_admin_user.role == 'customer'
redirect_to shipments_path
end
end
end
but produces error undefined method 'controller' for ActiveAdmin::Dashboards:Module (NoMethodError)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你知道这个地方: https://github.com/gregbell/active_admin/issues/501< /a>,那里有一些关于仪表板的好主意。
在dashboards.rb文件中渲染一个部分,如下所示:
然后从应该在app/views/admin/dashboard/_common_dashboard.html.erb创建的部分中,您可以访问current_admin_user对象:
另一种访问权限的方法dashes.rb '''environment''' 中的 current_admin_user 是使用 arbre 语法并像这样制定仪表板部分
I guess you know this place: https://github.com/gregbell/active_admin/issues/501, some good ideas about dashboards over there.
Render a partial within your dashboards.rb file with something like this:
Then from the partial, which you should create at app/views/admin/dashboard/_common_dashboard.html.erb you can access the current_admin_user object:
Another way to get access to the current_admin_user from the dashboards.rb '''environment''' is to use the arbre syntax and formulate your dashboard sections like so
您还可以使用 :if 条件限制仪表板部分,
因此仪表板将可供所有用户使用,但仅限于允许的部分
Aslo you can restrict dashboard sections with :if conditions,
so dashboard will be available for all users but only with allowed sections
您可以通过以下方式访问仪表板部分内的控制器操作
redirect_to
:you can access controller action
redirect_to
just inside dashboard section in this way: