RolifyCommunity / rolify

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

Rolify - errors with polymorphic associations #396

Open MincePie opened 8 years ago

MincePie commented 8 years ago

I'm getting a message from my heroku logs that I'm struggling to understand. I suspect it might have something to do with rolify.

I have the following models/associations:

[User

rolify
   attr_accessor :current_role

Role

class Role < ActiveRecord::Base

  has_and_belongs_to_many :users, join_table: "users_roles"
  belongs_to :resource, :polymorphic => true

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

  scopify

end
User_Roles join table has:

create_table "users_roles", id: false, force: :cascade do |t|
    t.integer "user_id"
    t.integer "role_id"
  end

  add_index "users_roles", ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree](url)
Preloading application
2016-04-22T04:09:58.023038+00:00 app[web.1]: [3] ! Unable to load application: ArgumentError: Unknown key: :polymorphic. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type
2016-04-22T04:09:58.023056+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.4/lib/active_support/core_ext/hash/keys.rb:75:in `block in assert_valid_keys': Unknown key: :polymorphic. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type (ArgumentError)

Can anyone make sense of this error? I wonder if it is something to do with the polymorphic statement on the Roles model? Or maybe that the join table isn't recognised on the user model (because rolify doesnt know that its called users_roles?

wldcordeiro commented 8 years ago

Could you give more details on your setup? What Rails and Rolify versions are you running?

MincePie commented 8 years ago

Rails: 4.2.4 Rolify: -5.0.0