我有一个Rails 3.2.x应用程序在后端使用了rails_admin
gem。我也在使用Devise进行身份验证,并在User
模型上有一个角色字段来说明用户是否是管理员或员工。Rails Admin config.authorize_with重定向用户如果不是管理员
我试图做的是建立了rails_admin授权,所以如果你访问http://domain.com/admin只会让它,如果current_user.role == "admin"
否则重定向到我家的控制器索引路径home_index_path
我设置的是初始应该这样做,并且如果角色不是管理员,它会拒绝管理员访问,但是我收到以下错误:No route matches {:controller=>"home"}
。我想这可能与routes.rb
有关,而我的RailsAdmin线路安装在routes.rb
中,但我不确定。最终,这应该检查角色以确保它等于admin,否则,redirect_to home_index_path并刷新消息。
任何帮助,非常感谢。
rails_admin.rb
RailsAdmin.config do |config|
config.authorize_with do |controller|
unless current_user.role == 'admin'
flash[:error] = "You are not an admin"
redirect_to home_index_path
end
end
end