我在设计中安装了 Rails_admin,我想将/admin 仪表板限制为只有管理员。目前我的代码看起来像:
config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)
正如您所看到的,用户可以进入仪表板,所以我只希望用户表的管理列中 bool 值为 true 的用户可以访问仪表板。
你会如何建议我这样做?
最佳答案
如果你不想使用 cancan 你可以这样做:
config.authorize_with do
redirect_to main_app.root_path unless current_user.try(:admin?)
end
我使用这个,它工作正常。
关于ruby-on-rails - Rails_admin 与设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27878324/