Skip to content


Wrong file path to precompiled asset files #14408

knagode opened this Issue · 24 comments

6 participants


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):

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'
Ruby on Rails member

Could you provide an application reproducing the bug?


Unfortunately it is private project - but I am ready to give you access to my computer over teamviewer. Is this an option?

Here is the preview of failing site:


@knagode not sure if it is an option. It would be nice to have an application (simple one) to reproduce this behavior, otherwise there is not too much to do :(
btw, I tried your application and everything looks normal to me.

Ruby on Rails member

When we say application it can be any application reproducing the issue. It would be better if it would a new rails application only with the minimal setup to reproduce.

@oveddan oveddan added a commit to oveddan/rails that referenced this issue
@oveddan oveddan This completes the work done for #14408 and #11432, which lets you ad…
…d the --model-name option when generating scaffold controllers.

This commit updates the path the generated code uses for redirection or links in the controller, views, and functional tests.

It also adds better test coverage to the generated code.
@oveddan oveddan added a commit to oveddan/rails that referenced this issue
@oveddan oveddan 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 helpers to use when using the --model-name option.

This updates the path the generated code uses for redirection or links in the controller, views, and functional tests.

It also updates the generated views to render the form resource using a namespace, if it's necessary

It also adds better test coverage to the generated code.

I'm closing this since there isn't an app to reproduce this behavior.

@knagode feel free to reopen if you provide an app to reproduce it. Thanks


+1 on this using rails 4.1.1.

When adding

<%= javascript_include_tag('lib/jquery-2.1.0.min.js', :recursive => true) %>

the generated code is not relative to assets but javascripts which is a wrong path:

<script recursive="true" src="/javascripts/lib/jquery-2.1.0.min.js"></script>

and a fail upon loading the page. This in any case is not consistent with the

documentation as it states that:

javascript_include_tag "xmlhr.js"
# => <script src="/assets/xmlhr.js?1284139606"></script> 

which is relative to assets and not assets/javascripts.

Note that removing the recursive option leads to:

<script src="/javascripts/lib/jquery-2.1.0.min.js"></script>

which is still not relative to assets and leads to a routing error in production.

(I use default Rails 4.1.1 production environnment (config.assets.compile = false)).

Ruby on Rails member

@muichkine where is your file?

It's expected to be inside app/assets/javascripts. So, app/assets/javascripts/lib/jquery-2.1.0.min.js.

The generated src will then be /assets/lib/jquery-2.1.0.min.js. What you're currently seeing is that it can't find the asset where it expects to, so assumes you'll later supply the file in public/javascripts/lib/jquery-2.1.0.min.js instead.


@matthewd The file is indeed app/assets/javascripts/lib/jquery-2.1.0.min.js. Now, the generated src is NOT /assets/lib/jquery-2.1.0.min.js but /javascripts/lib/jquery-2.1.0.min.js which is the problem.

Note that with config.assets.compile = true

<%= javascript_include_tag('lib/jquery-2.1.0.min.js') %>

works (so file is where expected).


@knagode I can try that. I use Azure as a production platform though, not Heroku.

Ruby on Rails member

When the assets pipeline is disabled (config.assets.compile = false) and the assets were no precompiled to generate the public/assts directory, the assets helpers try to find the files inside the public/#{assets_type} directory. So the behaviour you are getting is correct.


@rafaelfranca except that assets are precompiled (this is done automatically as part of my deployment script (capistrano)).

Ruby on Rails member

Is the manifest file inside your server?


@rafaelfranca if you are referring to the file public/assets/manifest-6ea009981f671e515368f79a4b83a508.json it indeed is. :)

Ruby on Rails member

So, we will need an application reproducing this issue. I could not reproduce in my rails 4.1.1 application.

Ruby on Rails member

Just a question. Is sprockets-rails and its railtie loaded in production?


@rafaelfranca yes, I think so since I include some headers from it:


require 'action_controller/railtie'
require 'action_mailer/railtie' 
require 'sprockets/railtie'
Ruby on Rails member

Weird. Is the lib/jquery-2.1.0.min.js listed inside the manifest file? Is it included in the precompile list?

I just tried to reproduce your issue in a new Rails 4.1.1 application and I could not


@rafaelfranca Nope!!!

 >> grep -r "jquery" manifest-6ea009981f671e515368f79a4b83a508.json 

returns nothing!

Ruby on Rails member

Ok, so we found your issue. :smile:

Is jquery.min.js included in the config.assets.precompile list?


@rafaelfranca No it's not.

I tried adding the whole subdirectory to it

config.assets.precompile << Rails.root.join('app','assets','javascripts','lib')

and running assets purge + precompile with no success so far.


OK got it, one has to add the files and not the dirs.

Thank you @rafaelfranca and @matthewd for your so valuable time!

Ruby on Rails member

You are welcome. With latests sprocket-rails you would get an exception in development and you would not have this problem in production. Make sure you are using it.


same issue..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.