rails dates with json

前端 未结 7 1592
你的背包
你的背包 2020-11-30 02:16

I am implementing a Facebook application and using AJAX/JSON.

However the JSON structures that are returned have this format 2010-05

相关标签:
7条回答
  • 2020-11-30 02:35

    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
    
    0 讨论(0)
提交回复
热议问题