• rails_admin 的管理权限设置 at 2016年08月22日

    請問我增加權限,使用 gem devise/cancancan/rolifty,model -> admin.rb and admin_ability.rb。

    請問我應該哪裡加 load_and_authorize_resource。目前都沒有權限效果。同時 admin role 都有加入 superadmin/admin/activeadmin 我加在這裡 rails_admin/app/controllers/rails_admin/main_controller.rb,這個出現錯誤 "uninitialized constant Main"

    請問怎麼解決呢?

    版本: gem 'rails', '~> 5.0.0.rc2' gem 'cancancan' gem "rolify" gem 'rails_admin', '1.0.0.rc'

    rails_admin.rb ... ## == Devise == config.authenticate_with do warden.authenticate! scope: :admin end

    config.current_user_method(&:current_admin)

    ## == Cancan == config.authorize_with :cancan, AdminAbility ...

    admin.ability.rb class AdminAbility include CanCan::Ability def initialize(user) if user && user.admin? can :access, :rails_admin
    can :dashboard if user.role? :superadmin can [:read, :create, :update], User # can :manage, :all elsif user.role? :admin can :manage, [Blog, BlogCategory, Video] can [:read, :create, :update], User elsif user.role? :activeadmin can :manage, [Event, EventAttendance, EventContact, User] can [:read, :update], User # can :update, Product, :hidden => false end end end end