将回形针 url 添加到 json [英] Add paperclip url to json

查看:46
本文介绍了将回形针 url 添加到 json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在 html 中我们会在 image 标签中使用 Model.field.url(:thumb),如何在 json 上做到这一点,尤其是使用 hash_secret.

Normally in html we will use Model.field.url(:thumb) inside image tag, How to do it on json, especially with hash_secret.

推荐答案

在您的模型中添加以下内容以获取 url(我相信这也适用于散列):

In your model add the following to get the url (I believe this also works with hashing):

def photo_url_thumb
    photo.url(:thumb)
end 

然后你可以像这样输出json:

And then you can output json like this:

 format.json { render :json => @model.photo_url_thumb }

这篇关于将回形针 url 添加到 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆