我正在尝试将一些代码推送到heroku。
我从heroku日志中收到此错误消息。我无法理解它。
就我可以破译而言,这与我的用户和角色模型有关,它们是:
用户
rolify
attr_accessor :current_role
has_and_belongs_to_many :roles, join_table: "users_roles"
作用
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连接表有:
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
任何人都可以理解此错误消息的含义吗?
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/associations.rb:1694: warning: already initialized constant User::HABTM_Roles
2016-04-22T03:11:57.250562+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/associations.rb:1694: warning: previous definition of HABTM_Roles was here
2016-04-22T03:11:58.690994+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-22T03:11:58.691033+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)
我刚刚发现下面的资源描述了'rolify'如何在用户模型中包含HABTM关系,因此它不需要作为关联单独列出,但我仍然会收到此错误:
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)
答案 0 :(得分:0)
部分回答 我刚刚发现了这个:https://github.com/RolifyCommunity/rolify/issues/315
如果你有&#39; rolify&#39;在用户模型中,您不需要编写HABTM角色
答案 1 :(得分:0)
此:
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
让我觉得它来自这条线:
belongs_to :resource, :polymorphic => true
因为这是我看到的唯一的多态键。我可能错了。