RolifyCommunity / rolify

Role management library with resource scoping
https://rolifycommunity.github.io/rolify/
MIT License
3.16k stars 404 forks source link

uninitialized constant Role::Resource when using paper_trail #334

Open olegantonyan opened 9 years ago

olegantonyan commented 9 years ago

Hi! I have a problem with rolify+paper_trail. My role model:

class Role < ActiveRecord::Base
  has_paper_trail
  scopify
  has_and_belongs_to_many :user_company_memberships, :join_table => :user_company_memberships_roles
  belongs_to :resource, :polymorphic => true

  validates :resource_type, :inclusion => { :in => Rolify.resource_types }, :allow_nil => true
  validates :name, presence: true, uniqueness: true, length: {:in => 2..30}
end

Trying to create a role:

Role.create(name: 'admin')
NameError: uninitialized constant Role::Resource
from /usr/local/lib/ruby/gems/2.2.0/gems/activerecord-4.2.1/lib/active_record/inheritance.rb:158:in `compute_type'

But without has_paper_trail it works just fine. Rails 4.2.1

ghost commented 9 years ago

Same here, would be good to have paper_trail enabled for the roles.