This project is archived and is in readonly mode.
Hashes with Time instances in it breaks when to_json is called on it.
-
Neeraj Singh
I tested it with rails edge.
I am not able to produce this problem with script/console.
ruby-1.8.7-p249 > {:date => Time.utc(2008, 5, 17)}.to_json => "{\"date\":\"2008-05-17T00:00:00Z\"}" ruby-1.8.7-p249 > {:date => Time.utc(2008, 5, 17)}.to_json => "{\"date\":\"2008-05-17T00:00:00Z\"}"I am not able to produce problem with rails runner
$ rails runner 'User.lab' {"date1":"2008-05-17T00:00:00Z"} class User < ActiveRecord::Base def self.lab t = Time.utc(2008, 5, 17) real = {:date1 => t}.to_json puts real end endHowever the attached test code is indeed failing which is really weird. Without digging dip into it I have a feeling that in test somewhere something is getting changed which is messing up to_json.
-
Santiago Pastorino
- Milestone cleared.
- Tag changed from activesupport, json, rails3 to activesupport, json, patch, rails3
- State changed from new to open
- Assigned user set to Yehuda Katz (wycats)
Neeraj try this and you will see the failure ...
>> santiago@debian:/tmp/myapp$ rails c Loading development environment (Rails 3.0.0.beta3) >> {:date => Time.utc(2008, 5, 17)}.to_json NoMethodError: undefined method `to_json' for {:date=>Sat May 17 00:00:00 UTC 2008}:Hash from (irb):1Here is a fix i think the code regarding to json on AS is not properly organized, i will refactor this at some point. -
August Lilleaas
@Neeraj Singh: Perhaps you have the json gem vendored elsewhere, or directly in the Gemfile, causing Rails to use that one instead of the bundled one? I'm also on edge rails, btw:
gem 'rails', :git => 'git://github.com/rails/rails.git'. -
Neeraj Singh
This is what I have in my Gemfile.
$ cat Gemfile source 'http://rubygems.org' #gem 'rails', '3.0.0.beta3' gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3-ruby', :require => 'sqlite3'in console
ruby-1.8.7-p249 > {:date => Time.utc(2008, 5, 17)}.to_json => "{\"date\":\"2008-05-17T00:00:00Z\"}"Really weird that I'm not able to reproduce it.
-
Repository
- State changed from open to committed
- Importance changed from to Medium
(from [926ca9c102db5034d4eb1ab0f915ea643145e284]) Load JSON additions (as to_json) on active_support/all.
[#4730 Hashes with Time instances in it breaks when to_json is called on it. state:committed]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/926ca9c102db5034d4eb1ab0f915ea... -
seamusabshere
- Assigned user changed from Yehuda Katz (wycats) to Santiago Pastorino
che Santiago,
I think the original problem remains:
$ gem list json *** LOCAL GEMS *** json (1.4.3) json_pure (1.4.3) $ gem list activesupport *** LOCAL GEMS *** activesupport (3.0.0.beta4, 2.3.8, 2.3.5) $ irb ruby-1.8.7-head > require 'rubygems' => true ruby-1.8.7-head > require 'active_support/json' => true ruby-1.8.7-head > { :hello => Time.now }.to_json ArgumentError: wrong number of arguments (2 for 1) from (irb):3:in `to_json' from (irb):3Best,
Seamus
