[英]rails 3 - paperclip
With paperclip, how can you get paperclip to use full urls like http://mysite.com/image/asdasd.png 使用回形针,如何使回形针使用完整的网址,例如http://mysite.com/image/asdasd.png
versus /image/asdad.png 与/image/asdad.png
thanks 谢谢
Once you configure the :url
interpolation string to your satisfaction, you can link to attachments with the full URL using something like: 配置:url
插值字符串后,您可以使用以下类似的链接链接到具有完整URL的附件:
def attachment_path(attachment)
attachment.url
end
def attachment_url(attachment)
"#{root_url}#{attachment.url.gsub(/^\//, '')}"
end
Assuming you want the behavior to work like the _url helpers on the controller/view level, its a little complicated as paperclip functions without the benefit of knowing the host from the request. 假设您希望该行为像控制器/视图级别上的_url帮助器一样工作,则它的回形针功能有点复杂,而无需从请求中了解主机。 An easy way to get around this is to define the constant HOST in the config/environments/ENV.rb and then passing the url parameter to has_attachment like 解决此问题的一种简单方法是在config / environments / ENV.rb中定义常量HOST,然后将url参数传递给has_attachment
:url => "http://#{HOST}/:path"
or whatever your url rules are. 或任何您的网址规则。
You can also side step this issue by using S3, which is kind of a life saver 您也可以通过使用S3来避免此问题,这可以节省生命
If you are uploading files to amazon S3 then 如果要将文件上传到Amazon S3,则
s3.urlgives the full image path. 给出完整的图像路径。 But in case of local file storage, you can set :url option also 但是在本地文件存储的情况下,您还可以设置:url选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.