Rails Fails To Generate Correct Link Path In Production Mode

70 views Asked by At

The app whose in production mode is failed to generate correct links. For instance, the code below

  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

is generating the code below:

  <link rel="stylesheet" media="all" href="/stylesheets/application.css" data-turbolinks-track="true" />
  <script src="/javascripts/application.js" data-turbolinks-track="true"></script>

I precompiled javascript and stylesheet. Their correct path is respectively /public/assets/application-0d1386df5e82480bb54a6cd082e626ed2d46d364e867ca7d9ce009d3af8c1718.js and /public/assets/application-5d8165dcf2b8902df77aed37c7ab6fee8c7d62844cb48ece6360d1fa4f079804.css.

Also, I did change config.assets.compile = true in /config/environments/production.rb. But nothing is changed.

1

There are 1 answers

0
Shani On

If you want to run production mode in your local environment you should tell rails to serve assets itself by changing following

config.serve_static_files = true

In production environment itself you have to configure it using nginx - http://vladigleba.com/blog/2014/03/27/deploying-rails-apps-part-4-configuring-nginx/

and make sure you have reverse your earlier change before pushing it to production.

config.serve_static_files = false