Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should look link the json response so that ActiveResource may generate a DateTime object from a date?

I have a question object with a created_at attribute in it. When I will find a question i get back the created_at from the REST service, but Activeresource do not convert the date string to DateTime.

Question.find(1)
/questions/1.json

Question.find(1).created_at.class
=> String

In which format should be the Json response, so that ActiveResource will convert it to a DateTime?

If it is not possible, what should i do?

like image 506
Piioo Avatar asked Mar 23 '23 01:03

Piioo


1 Answers

According to slide #14 in this presentation, you can do this in config/initializers/active_resource.rb:

ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
ActiveSupport.parse_json_times = true
like image 102
aqn Avatar answered Apr 06 '23 02:04

aqn