NoMethodError: undefined method `[]' for #<JSON::Ext::Generator::State:0x2407ea8>

438 views
Skip to first unread message

Rafi Jacoby

unread,
Jul 27, 2009, 9:38:49 PM7/27/09
to Ruby on Rails: Talk
Trying to move a project to Rails 2.3.3, and getting the following:

NoMethodError: undefined method `[]' for #<JSON::Ext::Generator::State:
0x2407ea8>
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/
active_support/json/encoders/hash.rb:45:in `as_json'
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/
active_support/json/encoders/hash.rb:34:in `to_json'

I understand that the to_json/as_json stuff changed, but this is for
something simple (using just hashes) like:

JSON.generate({"foo"=>"bar"})

I'm using latest json gem, tried requiring active_support before json,
and put this into my environment as suggested by the Rails upgrade
notes:

ActiveSupport::JSON.backend = 'JSONGem'

No dice.
If I use Rails 2.3.2, it's happy.

Anyone encounter/conquer this?

Tx,
Rafi

Rafi Jacoby

unread,
Jul 28, 2009, 12:45:00 PM7/28/09
to Ruby on Rails: Talk
After sleeping on it for a night, I replaced all instance of
'JSON.generate(hash)' with hash.to_json, solving the problem.

Posting this for posterity and those googling the issue.

snacktime

unread,
Jul 29, 2009, 1:25:08 AM7/29/09
to rubyonra...@googlegroups.com


On Mon, Jul 27, 2009 at 6:38 PM, Rafi Jacoby <rja...@astrokid.com> wrote:


Anyone encounter/conquer this?

 Ya, they changed how parse/generate works I think it accepts/returns arrays now.  Changing the behavior of a gem like that is wrong.  Can we get this changed back please?  

Chris
Reply all
Reply to author
Forward
0 new messages