Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

ruby on rails - Paperclip image url

Stupid question?

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

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

How can I get my path/url without it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...