2016-04-22 165 views
0

我試圖推動一些代碼到heroku。Rails 4 - 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

你可以嘗試將連接表重命名爲符號嗎?所以:user_roles而不是「user_roles」 –

+0

嗨,我只是試着將它從:join_table =:user_roles更改爲上面的方式。這對錯誤信息沒有任何影響。我試圖破譯錯誤意味着什麼?你能理解這個消息嗎? – Mel

回答

0

部分答案 我剛剛發現這一點:https://github.com/RolifyCommunity/rolify/issues/315

如果在用戶模式「rolify」,你不需要寫HABTM角色

+0

是的,我剛剛注意到了錯誤信息。 「/app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.4/lib/active_record/associations.rb:1694:警告:已經初始化爲常量User:HABTM_Roles」 –

+0

儘管此消息仍然出現,而我還有Heroku的應用程序錯誤:預加載應用程序 2016-04-22T04:09:58.023038 + 00:00 app [web.1]:[3]!無法加載應用程序:ArgumentError:未知的鍵::多態。有效的鍵是::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]: – Mel

+0

請參閱我的其他答案。我之前評論過並刪除了它,因爲我認爲你已經解決了這個問題,但它是:引起錯誤的多元真實位。 –

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 

,因爲這是唯一的多態的關鍵我看。但我可能是錯的。

+0

我認爲這也可能是,但是我評論你:多態性=>真實位,並再次嘗試,但我仍然得到相同的錯誤 - 所以它不是那個 – Mel

+0

事實上,完全刪除該行仍然給出相同的錯誤 – Mel

相關問題