Search code examples
ruby-on-railsrubyassets

Rails 5 unable to load assets in production mode


I am able to precompile assets in public/assets directory of rails application. But when I start application in production, rails constructing wrong path and not pointing to the precompiled assets.

System environment details are as below.

rails -v
Rails 5.0.4

ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]

"sprockets-rails", '2.3.3'

and production.rb

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = true

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

and asset.rb

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w( *.js *.css *.js.erb *.css.erb)

And my index.html.erb looks this way

<%=javascript_include_tag "bootstrap.min"%>
<%=stylesheet_link_tag "bootstrap.min"%>

and the rails trying to fetch assets using below paths,

enter image description here

and the compiled assets in folders looks as bellow.

enter image description here

Kindly help me to find out where I am going wrong. Thanks in advance and any help appreciated.


Solution

  • Make sure the digest setting is enabled:

    config.assets.digest = true