0
class Request 
include Mongoid::Document 
field :code, type: String  
validates :code, :presence => true, 
       :inclusion => { :in => proc { Listing.all_codes } } 

使用Mongoid,我試圖驗證:提交表單上輸入代碼,以確保他們使用的是正確的代碼已在數據庫中。列表模型:代碼字段也被命名爲:代碼。的Rails 3:Mongoid validates_inclusion_of錯誤

這是錯誤:

有什麼建議? Mongoid中的參考等價物是什麼?

回答

0

這是紅寶石級別的錯誤說你沒有一種方法看起來像

class Listing 
    def self.all_codes 
     # stuff 
    end 
end 

self.部分是很重要的。

你可能有它實現像

class Listing 
    named_scope :all_codes, :select => #... 
end 

你可能只是想Listing.all真正的錯誤是你的Request類和你的清單類之間的方法名分歧。