我需要通过 url 获取一些图片。
网址类似于 http://img.wallsbay.com/large/2014/05/2665.jpg但 2014 和 2665 正在发生变化。
我的 Controller 有这个参数:
def image_params
params.require(:image).permit(:content, :remote_content_url, :id)
end
我试着像这样从 url 中获取图像:
@image.remote_content_url = 'http://img.wallsbay.com/large/#{:content}/05/#{:id}jpg'
但是 remote_content_url 是未定义的方法。
最佳答案
remote_<attr_name>_url
属性是通过给定的 URL 上传图片。
@model.remote_content_url = "http://img.wallsbay.com/large/2014/05/2665.jpg"
@model.save
@model.content_url // => "<upload-dir>/2665.jpg"
使用 @model.content_url
检索上传图片的 url。
要应用转换,请使用 @model.content_url(:square)
.
关于ruby-on-rails - Carrierwave通过url获取图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39074740/