Rails 3:使用特定变量返回JSON

时间:2011-08-07 11:24:38

标签: ruby-on-rails-3 json

我有一个方法返回:

  format.json  { render :json => @call, :include => :customer }

但是,我希望@call.created_at作为更易读的日期时间返回。

我该怎么做?

感谢

1 个答案:

答案 0 :(得分:1)

您可以在模型中创建一个方法来美化时间。

class Call < ActiveRecord::Base
  def formatted_time
    #Pretty time
  end
end

format.json  { render :json => @call, :include => :customer, :methods => :formatted_time }