rails dates with json

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

Leave a Comment