我是Rails的新手,尤其是rails_admin。 如何在尝试访问管理页面时通知登录前端的用户没有ADMIN? 谢谢。 这是index.html.erb
if (fbuf.st_size !=0) fseek(file, 0, SEEK_SET);
答案 0 :(得分:0)
application.html.erb
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
应用程序控制器
class ApplicationController < ActionController::Base
...
rescue_from CanCan::AccessDenied do |exception|
redirect_to main_app.root_path, alert: exception.message
end
应用程序/模型/ ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.roles.include? :admin
can :manage, :all
else