Tôi có đoạn code công ty sau đây:chính Unknown gắn Rails
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
Nó đặt ra một lỗi:
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
Tôi cố gắng để thay đổi dòng đầu tiên thành:
has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy,-> { where(:dimension => nil) }
Nhưng nó cũng đưa ra một lỗi, bạn có thể chỉ cho tôi những gì là sai với nó?
Đã chỉnh sửa câu hỏi để bao gồm mã nguồn từ một trang web bên ngoài. Từ [SO help] (http://stackoverflow.com/help/how-to-ask): "Nếu có thể tạo ví dụ trực tiếp về sự cố mà bạn có thể liên kết tới (ví dụ: trên http: // sqlfiddle.com/ hoặc http://jsbin.com/) sau đó làm như vậy - nhưng cũng bao gồm mã trong chính câu hỏi của bạn. Không phải ai cũng có thể truy cập các trang web bên ngoài và liên kết có thể bị hỏng theo thời gian ". – Amadan
Cảm ơn bạn đã chỉnh sửa và báo giá :) –
Lỗi bằng ký hiệu -> là gì? – JTG