回形针图片网址 [英] Paperclip image url

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

问题描述

愚蠢的问题?

<img alt="Phone_large" src="/system/photos/1/small/phone_large.jpg?1238845838" />

为什么要在图片路径中添加?1238845838"?

Why is "?1238845838" added to the image path?

没有它我如何获得我的路径/网址?

How can I get my path/url without it?

推荐答案

它通常被称为缓存破坏者".Paperclip 会自动附加上次文件更新的时间戳.

It's commonly referred to as a "cache buster". Paperclip automatically appends the timestamp for the last time the file was updated.

假设您要移除缓存破坏器并使用 /system/photos/1/small/phone_large.jpg 代替.当您更改图片时,网址不会更改,并且只要您的访问者缓存了旧图片,他们就会看到旧图片.

Say you were to remove the cache buster and use /system/photos/1/small/phone_large.jpg instead. The URL wouldn't change when you changed the image and your visitors would see the old image for as long as they had it cached.

如果你想删除它,只需调用 .url(:default, timestamp: false).当然,您可以将 :default 更改为您定义的任何其他样式.

If you want to remove it just call .url(:default, timestamp: false). Of course you can change :default to any other style you've defined.

或者,如果您想全局默认关闭它们,只需将其放在 config/initializers/paperclip.rb 文件中即可.

Or if you want to globally default them to off, just put this in a config/initializers/paperclip.rb file.

Paperclip::Attachment.default_options[:use_timestamp] = false

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

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