Skip to content


CanCan doesn't accepts module association scope #789

radeno opened this Issue · 1 comment

2 participants



i just cleanup my application and want to organize my structure to modules and one of them is whole user accounts (with roles, licenses, etc).

Association in namespaced models are scoped within module and is not need to define another class name

In my module have models:
User, Role associated through UserRole.

In my Ability.rb is this definition:

can :manage, Access::User, roles: { name: ['admin', 'editor', 'author'] }

Without defined class_name in association cancan returns: uninitialized constant Role

When i add class_name to association:

module Access
  class User < ActiveRecord::Base
    has_many    :user_roles,          inverse_of: :user
    has_many    :roles,               through: :user_roles, class_name: 'Access::Role'

It working.


Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still.
Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (

We hope to see you on the other side!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.