Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Rolify in namespaced model #567

Open
chrisgeek opened this issue Aug 9, 2021 · 1 comment
Open

Using Rolify in namespaced model #567

chrisgeek opened this issue Aug 9, 2021 · 1 comment

Comments

@chrisgeek
Copy link

I have a user class namespaced in a user_base module, below are the two models
role model

module Userbase
class Role < ApplicationRecord
  has_and_belongs_to_many :users, :join_table => :users_roles
  
  belongs_to :resource,
             :polymorphic => true,
             :optional => true
  

  validates :resource_type,
            :inclusion => { :in => Rolify.resource_types },
            :allow_nil => true

  scopify
end
end

user model

module Userbase
  class User < ApplicationRecord
    rolify 
  end
end

I get the following error when I try to add a role to a user user.add_role? :admin
NameError: uninitialized constant Role
I am not sure why I am getting this error.
The join table is users_roles as expected

@thomas-mcdonald
Copy link
Member

I think you need to pass an argument to rolify to pick up the correct roles location. From the test suite:

rolify :role_cname => "Admin::Right"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants