diff options
Diffstat (limited to 'app/helpers/application_helper.rb')
| -rw-r--r-- | app/helpers/application_helper.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 87aa82c..0d28661 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb | |||
| @@ -15,4 +15,18 @@ module ApplicationHelper | |||
| 15 | def resolve_kind_text(value) | 15 | def resolve_kind_text(value) |
| 16 | value.respond_to?(:call) ? value.call : value | 16 | value.respond_to?(:call) ? value.call : value |
| 17 | end | 17 | end |
| 18 | |||
| 19 | # Cache-busts a static file living directly under public/, outside the | ||
| 20 | # asset pipeline -- used by both the admin and public layouts, since | ||
| 21 | # neither loads its static CSS/JS through Sprockets (admin_bundle.js is | ||
| 22 | # the one exception; it already gets pipeline fingerprinting for free). | ||
| 23 | # Raises rather than silently omitting the version param: a missing | ||
| 24 | # file here means the page is already broken, and failing loudly beats | ||
| 25 | # a confusing "why is the browser still showing the old version" report | ||
| 26 | # days later. | ||
| 27 | def mtime_busted_path(path) | ||
| 28 | file = Rails.public_path.join(path.sub(%r{\A/}, "")) | ||
| 29 | raise "Static asset not found for cache-busting: #{path} (looked for #{file})" unless File.exist?(file) | ||
| 30 | "#{path}?v=#{File.mtime(file).to_i}" | ||
| 31 | end | ||
| 18 | end | 32 | end |
