Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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 carrierwave升级和在json中充当api响应的问题_Ruby On Rails_Json_Ruby On Rails 3_Carrierwave - Fatal编程技术网

Ruby on rails carrierwave升级和在json中充当api响应的问题

Ruby on rails carrierwave升级和在json中充当api响应的问题,ruby-on-rails,json,ruby-on-rails-3,carrierwave,Ruby On Rails,Json,Ruby On Rails 3,Carrierwave,我正在使用acts作为api和carrierwave。我有以下代码: # in the model mount_uploader :avatar, ImageUploader mount_uploader :profile_cover, ImageUploader api_accessible :basic do |t| t.add :avatar t.add :profile_cover end # in the controller render :json => reso

我正在使用acts作为api和carrierwave。我有以下代码:

# in the model
mount_uploader :avatar, ImageUploader
mount_uploader :profile_cover, ImageUploader

api_accessible :basic do |t|
  t.add :avatar
  t.add :profile_cover
end

# in the controller
render :json => resource.as_api_response(:basic)
现在我已将Carrierwave从0.5.8升级到0.8,json响应有所不同:

# With carrierwave 0.5.8
{
  "avatar":{
    "url":"/uploads/avatar.jpg"
  },
  "profile_cover":{
    "url":"/uploads/profile_cover.jpg"
  }
}

# With carrierwave 0.8.0
{
  "avatar":{
    "avatar":{
      "url":"/uploads/avatar.jpg"
    }
  },
  "profile_cover":{
    "profile_cover":{
      "url":"/uploads/profile_cover.jpg"
    }
  }
}

有没有办法像升级前那样显示json而不重复元素?

你找到答案了吗?没有,我不得不将我的应用程序更改为使用新的json格式,很抱歉没有帮助:(无论如何,谢谢你的回复:)