Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Rails 3:返回带有特定变量的JSON_Ruby On Rails 3_Json - Fatal编程技术网

Ruby on rails 3 Rails 3:返回带有特定变量的JSON

Ruby on rails 3 Rails 3:返回带有特定变量的JSON,ruby-on-rails-3,json,Ruby On Rails 3,Json,我有一个方法返回这个: format.json { render :json => @call, :include => :customer } 但是,我希望在处创建的@call.created_作为更可读的日期时间返回 我该怎么做 谢谢您可以在模型中创建一个方法来美化时间 class Call < ActiveRecord::Base def formatted_time #Pretty time end end format.json { ren

我有一个方法返回这个:

  format.json  { render :json => @call, :include => :customer }
但是,我希望在处创建的
@call.created_作为更可读的日期时间返回

我该怎么做


谢谢

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

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

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

这不应该起作用吗:def-formatted\u time this.created\u at=this.created\u在.strftime(“%d--%m--%Y”)结束时?不只是def-formatted\u time这个。created\u在.strftime(“%d--%m--%Y”)结束时