Search code examples
ruby-on-railsruby-on-rails-3asset-pipelineproduction-environment

assets rails 3.1 not load after precompile nginx + unicorn


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:

enter image description here

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


Solution

  • 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!