这就是我所拥有的:
def index
@attachments = current_user.attachments.all
respond_to do |format|
format.json do
render :json => @attachments.map { |o| { url: o.picture.thumb.url }}
end
end
end
=> [{:网址 =>" /uploads/attachment/picture/7/thumb_df3c0c3c.jpg"},{:网址 =>&# 34; /uploads/attachment/picture/12/thumb_dd7839ee.jpg"},...}]
如何将密钥从:url 更改为:thumb ?
=> [{:thumb=>"/uploads/attachment/picture/7/thumb_df3c0c3c.jpg"},
{:thumb=>"/uploads/attachment/picture/12/thumb_dd7839ee.jpg"}, ... }]
以下是整个对象: render:json => @attachments
我的目标:拇指:拇指:" /上传/附加......"
背景:https://www.froala.com/wysiwyg-editor/docs/concepts/image-manager
我使用gem carrierwave创建一个拇指
答案 0 :(得分:2)
response.map! { |urls| { :thumb => urls[:url] } }
答案 1 :(得分:1)
更改" url"到"拇指"
render :json => @attachments.map { |o| { **thumb: o.picture.thumb.url** }}