2010-09-27 61 views
0

我有一個名爲類,看起來像這樣:to_json不工作,因爲反射是錯

class Foo < ActiveRecord::Base 
    belongs_to othermodel 
end 

和一類酒吧,看起來像這樣:

class Bar < Foo 
    belongs_to thirdmodel 
end 

當我嘗試使用bar.first.to_json(:include =>:othermodel)序列化bar,但它在生產模式下失敗。奇怪的是它在 的開發環境中工作。我四處挖掘,發現在生產模式下,bar.first.class.reflections.keys僅包含「thirdmodel」,而不包含 「othermodel」。

我不能解釋,在軌道2和開發環境中,它 工作完美。

錯誤是:

NoMethodError: undefined method `macro' for nil:NilClass 
    from ~/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/active_record/serialization.rb:41:in `block in serializable_add_includes' 

回答

0

問題是思考斯芬克斯。刪除它並用自己的解決方案替換它,現在它完美地工作。