assets rails 3.1 not load after precompile nginx + unicorn

此生再无相见时 提交于 2019-12-10 18:33:47

问题


I am trying precompile assets in production env. But after precompile the app does not find the images files, javascripts files, css files...etc.

I run this command:

RAILS_ENV=production rake assets:precompile

and I get this result:

/home/hyperrjas/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /home/hyperrjas/.rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/home/hyperrjas/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /home/hyperrjas/.rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets

then I try reload the page and I see this:

I'm using nginx + unicorn.

Why the app not find the assets, images, css, javascript...

Edited**

I load my assets layout from application.html.erb with:

<%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag "application" %>

I have in my nginx.conf this in server { }

location ~ ^/(assets)/  {
                          root ~/mydomain.com/current/public;
                          gzip_static on; # to serve pre-gzipped version
                          expires max;
                          add_header  Cache-Control public;
                         }

Thank you


回答1:


The problem was fixed :D:

The error was in nginx.conf in:

location ~ ^/(assets)/  {
                         root ~/mydomain.com/current/public;
                         gzip_static on; # to serve pre-gzipped version
                         expires max;
                         add_header  Cache-Control public;
                        }

The path to root to assets is bad, the correct form is:

 location ~ ^/(assets)/  {
                            root /home/hyperrjas/mydomain.com/current/public;
                            gzip_static on; # to serve pre-gzipped version
                            expires max;
                            add_header  Cache-Control public;
                           }

Thank you!




回答2:


First,

Can you check - Manifest Files and Directives app/assets/javascripts/application.js it should be

// ...
//= require jquery
//= require jquery_ujs
//= require_tree

app/assets/stylesheets/application.css

/* ...
*= require_self
*= require_tree .
*/

Check, below setting in config/environment/production.rb in your application It should be true

config.assets.compile = true

and if you want a digests for assets URLs, make below true if it is false.

config.assets.digest = true

Few reference links

http://mrjaba.posterous.com/rails-31-asset-pipeline-with-nginx-and-passen

http://guides.rubyonrails.org/asset_pipeline.html



来源:https://stackoverflow.com/questions/9825737/assets-rails-3-1-not-load-after-precompile-nginx-unicorn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!