railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.88k stars 2.25k forks source link

rails_admin 3.1.0 causes error when referencing Ability class in initializer as described in wiki #3563

Closed okuramasafumi closed 1 year ago

okuramasafumi commented 1 year ago

Describe the bug

https://github.com/railsadminteam/rails_admin/wiki/CanCanCan#use-different-ability-classes-for-front-end-and-admin

Loading an ability class located in app/models/abilities directory, it causes an error.

Reproduction steps

When I follow the description of this wiki page and configure RailsAdmin like below:

# MyAbility class is located in app/models/abilities/my_ability.rb
config.authorize_with :cancancan, Abilities::MyAbility

the following error occurs:

The constant Abilities is not loaded yet upon the execution of the RailsAdmin initializer.
We don't recommend to do this and may lead to issues, but if you really have to do so you can explicitly require it by adding:

  require 'abilities'

on top of config/initializers/rails_admin.rb.

Expected behavior

We should be able to specify the custom ability class located in abilities directory.

Suggestion

I'd like to suggest the following way:

config.authorize_with :cancancan, 'Abilities::MyAbility'

so that we can later classify the given string.

Additional context

Add any other context about the problem here.

codealchemy commented 1 year ago

Documentation updated (the change in RailsAdmin happened in https://github.com/railsadminteam/rails_admin/commit/f84ca1c7abc9c6685802ddb62f52ffc6e5008e55), thanks for the report!