2014-07-08 5 views
8

मैं निम्नलिखित संघों कोड है:अज्ञात कुंजी

has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy,-> { where(:dimension => nil) } 

:

Unknown key: :conditions. Valid keys are: :class_name, :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 

मैं में पहली पंक्ति को बदलने की कोशिश:

has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", 
    :dependent => :destroy, :conditions => {:dimension => nil} 
has_many :raters_without_dimension, :through => :rates_without_dimension, 
    :source => :rater 

has_one :rate_average_without_dimension, :as => :cacheable, 
    :class_name => "RatingCache", 
:dependent => :destroy, :conditions => {:dimension => nil} 


dimensions.each do |dimension|   
    has_many "#{dimension}_rates", :dependent => :destroy, 
    :conditions => {:dimension => dimension.to_s}, 
    :class_name => "Rate", 
    :as => :rateable 

    has_many "#{dimension}_raters", :through => "#{dimension}_rates", 
    :source => :rater   

    has_one "#{dimension}_average", :as => :cacheable, :class_name => "RatingCache", 
    :dependent => :destroy, :conditions => {:dimension => dimension.to_s} 
end 

यह एक त्रुटि को जन्म देती है लेकिन यह भी एक त्रुटि उठाया, क्या आप मुझे बता सकते हैं कि इसमें क्या गलत है? मैं उदाहरणों में देख के रूप में

+2

बाहरी साइट से स्रोत कोड शामिल करने के लिए प्रश्न संपादित किया गया हो। [एसओ सहायता] से (http://stackoverflow.com/help/how-to-ask): "यदि समस्या का एक लाइव उदाहरण बनाना संभव है जिसे आप लिंक कर सकते हैं (उदाहरण के लिए, http: // पर sqlfiddle.com/ या http://jsbin.com/) फिर ऐसा करें - लेकिन अपने प्रश्न में कोड भी शामिल करें। हर कोई बाहरी साइटों तक नहीं पहुंच सकता है, और लिंक समय के साथ टूट सकते हैं। " – Amadan

+0

आपके संपादन और उद्धरण के लिए धन्यवाद :) –

+0

-> नोटेशन का उपयोग कर त्रुटि क्या थी? – JTG

उत्तर

9

एक ही समस्या यहाँ https://teamtreehouse.com/forum/unknown-key-conditions

वर्णित है, शर्त के साथ लैम्ब्डा है संघ नाम के बाद, क्योंकि {} बिना हैश के रूप में ही अंतिम तर्क हो सकता है चाहिए।

प्रयास करें

has_many :rates_without_dimension, -> { where(dimension: nil) }, as: :rateable, class_name: "Rate", dependent: :destroy 

पी.एस. आप http://apidock.com/rails/Object/with_options का उपयोग कर सकते हैं ताकि यह अच्छी तरह से

संबंधित मुद्दे