1
  • Now, i had a problem about assets:precompile on production.
  • When i run bundle exec rake assets:precompile RAILS_ENV=production. My website can't load javascript file and css file.
  • But when i ran it on development environment, everything were well.

  • The problem was here if in config/environments/production.rb, and i set this line was true same as config.assets.compile = true. Everything was fine.

  • But when i set default same as config.assets.compile = false. My website can't load css file and javascript file. Hope everybody can explain for me ? Thank you very much.

Here is my application.css vs application.js

/*
*= require_self
*= require_tree .
*/

This is my application.js file:

//= require jquery_ujs
//= require jquery-ui.min
//= require plugins/back-to-top

And this is application.html.erb

<%= stylesheet_link_tag  'application', media: 'all'%>
<%= javascript_include_tag "application" %>
Khanh Pham
  • 2,848
  • 2
  • 28
  • 36

1 Answers1

1

In rails previously the assets were placed in public folder but now all the assets are located in the assets folder. The setting:

config.assets.compile = true

makes the live compilation enabled. In the live compilation all the assets are handled by sprockets. In the first time the assets is cached and compiled and their names are altered using a MD5 hash.

Now you have precompiled assets which gets stored in the public folder and to server assets from public folder you need to set:

config.serve_static_files = true

So set it to true and restart the server and check again.

More details:

http://guides.rubyonrails.org/asset_pipeline.html#in-production

Deepesh
  • 6,138
  • 1
  • 24
  • 41
  • Thank you very much. When i set `config.serve_static_files = true`, it worked very well. And why i didn't want to set `config.assets.compile = true` because i read a topic, and the topic said that if i set the value is true, it was slow. This is link of topic: [5. Don't fall back in staging or production] https://www.reinteractive.net/posts/116-12-tips-for-the-rails-asset-pipeline Thank you very much. – Khanh Pham Jul 09 '15 at 12:42
  • @KhanhPham: this will help you regarding your doubt http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not and you can always accept the answers if it helped you so if others faces the same issue this might help – Deepesh Jul 09 '15 at 13:10