I have a rails app with CSS/JS that works fine in development. In production, precompilation of assets goes fine. The resources are in the right locations, and everything is linked properly as far as I can tell.
The problem is, despite having the seemingly correct CSS in these files, it's not actually applying on the page. What does work is if I go into the editor, cut all the compiled CSS and repaste it. Then all the CSS applies.
Production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :debug
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
nginx.conf partial
server {
listen 80 default;
server_name example.com;
root /home/appuser/current/public;
# access_log /var/log/nginx/access.log;
rewrite_log on;
location / {
#all requests are sent to the UNIX socket
proxy_pass http://example;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~ ^/assets/ {
root /home/appuser/current/public;
gzip_static on;
expires max;
add_header Cache_Control public;
}
}
As I suspected, the CSS (and JS) was being loaded after the page was. I moved the asset block in the nginx config above the root location block and now things are working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.