rails: Wrong file path to precompiled asset files
I precompile my assets and use following function to render html:
= stylesheet_link_tag "frontend/application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "frontend/application", "data-turbolinks-track" => true
Sometimes those methods generate correct html markup (assets are in assets folder and have fingerprint in filename):
<link data-turbolinks-track="true" href="/assets/frontend/application-64cf06dd4d2386f145e00844fed60d28.css" media="all" rel="stylesheet" /> <script data-turbolinks-track="true" src="/assets/frontend/application-447281961c979f73e944369c4b832fd8.js"></script>But on production (Heroku) rails sometimes (50%!) generates html markup like this (folder structure is not OK)
<link data-turbolinks-track="true" href="/stylesheets/frontend/application.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/javascripts/frontend/application.js"></script>
Any idea what could be wrong or how can I fix/debug this? The strangest thing is because it behaves kind of randomly 😦
Below is my production config.
config.assets.enabled = true
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true # rails_12factor gem will sett this to true on heroku
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = false
# Compress JavaScripts and CSS.
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 26 (12 by maintainers)
Commits related to this issue
- This completes the work done for #14408 and #11432, which lets you add the --model-name option when generating scaffold controllers. This commit updates the path the generated code uses for redirecti... — committed to oveddan/rails by oveddan 10 years ago
- This completes the work done for #14408 and #11432, which adds the --model-name option when generating scaffold controllers. What was missing from the original work was correctly generating the route... — committed to oveddan/rails by oveddan 10 years ago
- Clear tmp/cache files after precompiling Possible fix for: https://github.com/openfoodfoundation/ofn-install/issues/633 See: https://github.com/rails/rails/issues/14408#issuecomment-290257247 — committed to Matt-Yorkley/ofn-install by Matt-Yorkley 4 years ago
After knocking my head against the wall for at least an hour (maybe more, I lost track). I deleted the cache (rm -r tmp/cache in my case) and suddenly the markup started to fit the assets path.