2011-12-05 12 views
0

考慮下面的代碼在初始化:誤差validates_each

module ValidatesAssociatedAttributes 
    module ActiveRecord::Validations::ClassMethods 
    def validates_associated(*associations) 
     class_eval do 
     validates_each(associations) do |record, associate_name, value| 
      #empty for now 
     end 
     end 
    end 
end 
end 

我得到的錯誤:

undefined method `to_sym' for {:message=>nil}:Hash 

我難倒。據我所知,協會有預期的數據。通常,當我開始獲取to_sym錯誤時,意味着存在某些配置錯誤,但在這種情況下,我只是使用簡單的jane validates_associated。我沒有得到什麼/爲什麼需要去猜測。

+1

發佈錯誤沒有一個堆棧跟蹤就像告訴一個笑話,但沒有留下深刻的印象。 – tadman

回答

0

後更清晰地閱讀,我發現,我flubbed它的API: 我需要圖示協會爲validates_each接受一切都在正確的順序:

module ValidatesAssociatedAttributes 
    module ActiveRecord::Validations::ClassMethods 
    def validates_associated(*associations) 
     class_eval do 
     validates_each(*associations) do |record, associate_name, value| 
      #empty for now 
     end 
     end 
    end 
end 
end