views:

56

answers:

2

hello am implementing a facebook application and am using AJAX/Json,however the json structures that are returned have this format "2010-05-30T06:14:00Z" , I am using Game.all.to_json

how can i convert them to a normal date format ? Is it easier to do it from the server side or the client side using fbjs? (there are a lot of bugs with fbjs so i would prefer using a solution from the server side , like converting the data before sending the json structures)

thnak you

A: 

Definitely easier to do it on the server side. You can do a gsub regex to put it into the format you want, or a time.strftime, then generating your json with that string.

porkeypop
A: 

The way I added my own custom format to the json I was returning was to add a monkey patch to the ActiveSupport TimeWithZone class.

Add a file in the config/initializers folder with the following contents:

class ActiveSupport::TimeWithZone
    def as_json(options = {})
        strftime('%Y-%m-%d %H:%M:%S')
    end
end
Philz