0

我正在使用acts_as_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?

4

0 回答 0