Rails 3.1.3 및 JSON gem 1.6.3을 실행하는 프로젝트가 있고 ActiveRecord 인스턴스를 JSON.dump로 전달할 수 없습니다. 나는 항상 다음과 같은 오류 얻을 :ActiveRecord 객체의 JSON.dump가 실패합니다.
NoMethodError: undefined method `[]=' for #<JSON::Ext::Generator::State:0x000001033f2088>
from /Users/andy/.rvm/gems/[email protected]/gems/activerecord-3.1.3/lib/active_record/serialization.rb:10:in `serializable_hash'
from /Users/andy/.rvm/gems/[email protected]/gems/activemodel-3.1.3/lib/active_model/serializers/json.rb:84:in `as_json'
from /Users/andy/.rvm/gems/[email protected]/gems/activesupport-3.1.3/lib/active_support/json/encoding.rb:47:in `block in encode'
from /Users/andy/.rvm/gems/[email protected]/gems/activesupport-3.1.3/lib/active_support/json/encoding.rb:78:in `check_for_circular_references'
from /Users/andy/.rvm/gems/[email protected]/gems/activesupport-3.1.3/lib/active_support/json/encoding.rb:46:in `encode'
from /Users/andy/.rvm/gems/[email protected]/gems/activesupport-3.1.3/lib/active_support/json/encoding.rb:31:in `encode'
from /Users/andy/.rvm/gems/[email protected]/gems/activesupport-3.1.3/lib/active_support/core_ext/object/to_json.rb:20:in `to_json'
from /Users/andy/.rvm/gems/[email protected]/gems/json-1.6.3/lib/json/common.rb:216:in `generate'
from /Users/andy/.rvm/gems/[email protected]/gems/json-1.6.3/lib/json/common.rb:216:in `generate'
from /Users/andy/.rvm/gems/[email protected]/gems/json-1.6.3/lib/json/common.rb:380:in `dump'
JSON.dump 등등 해시, 비 액티브 클래스의 인스턴스, 잘 작동 전달을하고, #to_json 내 액티브 인스턴스에서 작동합니다. 대신 실제로 #to_json을 호출 할 수는 없지만 실제로 라이브러리 인 것처럼 JSON.dump를 호출하는 ActiveRecord 객체를 전달하고 있습니다. 그러나 나는 다른 라이브러리를 건너 뛰고 그냥 JSON.dump를 호출하는 것과 같은 문제를 안고있다.
도움을 주시면 감사하겠습니다.