【发布时间】:2015-02-13 10:09:50
【问题描述】:
我有一个用户模型,它为名为 profile_img 的字段安装载波上传器。代码如下:
class User < ActiveRecord::Base
mount_uploader :profile_img, ProfileUploader
end
profile_img 字段的输出是这样的:
"profile_img": {
"url": "https://halo-img-dev.s3.amazonaws.com/uploads/user/profile_img/1000/cola_iOS2_512_dribbble2.png",
"thumb": {
"url": "https://halo-img-dev.s3.amazonaws.com/uploads/user/profile_img/1000/thumb_cola_iOS2_512_dribbble2.png"
},
"medium": {
"url": "https://halo-img-dev.s3.amazonaws.com/uploads/user/profile_img/1000/medium_cola_iOS2_512_dribbble2.png"
}
}
当我尝试通过简单地调用 super 来自定义序列化哈希时,
def serializable_hash(options = {})
super(options)
end
profile_image 字段键被复制
"profile_img": {
"profile_img": { #### duplicate here
"url": "https://halo-img-dev.s3.amazonaws.com/uploads/user/profile_img/1000/cola_iOS2_512_dribbble2.png",
"thumb": {
"url": "https://halo-img-dev.s3.amazonaws.com/uploads/user/profile_img/1000/thumb_cola_iOS2_512_dribbble2.png"
},
"medium": {
"url": "https://halo-img-dev.s3.amazonaws.com/uploads/user/profile_img/1000/medium_cola_iOS2_512_dribbble2.png"
}
}
},
我怀疑这个问题源于载波序列化方法,但找不到解决方案。
有什么线索吗?
【问题讨论】:
标签: serialization rails-activerecord carrierwave jsonserializer