This project is archived and is in readonly mode.
Rails 3 to_json incompatible with JSON core library
-
Fluxx
We're running in to this inside of Rails3 beta4 as well:
Loading development environment (Rails 3.0.0.beta4) irb(main):001:0> Rails.version => "3.0.0.beta4" irb(main):002:0> {1=>2}.to_json => "{\"1\":2}" irb(main):003:0> {1=>:a}.to_json ArgumentError: wrong number of arguments (2 for 1) from (irb):3:in `to_json' from (irb):3 irb(main):004:0> {1=>{2=>:a}}.to_json ArgumentError: wrong number of arguments (2 for 1) from (irb):4:in `to_json' from (irb):4 irb(main):006:0> {1=>{2=>1}}.to_json => "{\"1\":{\"2\":1}}" @@@@ In particular, it seems to only happen when the value of a hash is a symbol. -
Rasmus Rønn Nielsen
I think this is a duplicate of:
https://rails.lighthouseapp.com/projects/8994/tickets/4494-ruby-192... -
iuri matias
We are running into the same problem
-
Jeremy Kemper
- State changed from new to duplicate
- Importance changed from to Low
JSON gem overloads
to_jsonwith its own private encoding API so we'll continue to run into these issues until that lib changes its approach. -
Nate Wiger
For others wondering, the only way I've found to workaround this is to put this in environment.rb, after the initializer block
class Array def to_json(*a) ActiveSupport::JSON.encode(self) end endThis also works for Sinatra/etc if you put it in the main application.rb file (or whatever yours is called).
-Nate