roger
roger

Reputation: 9893

Ruby on Rails application can not find stylesheets and javascript in production environment?

I deploy a Ruby on Rails application in ubuntu with passenger and nginx, but it cannot find the css and js files in my application.

Here is the error message:

open() "/var/nginx/blog/public/stylesheets/application.css" failed (2: No such file or directory)

In fact, /var/nginx/blog/public/stylesheets/application.css don't exist actually, my js files is in /var/nginx/blog/app/assets/javascripts/, my css files is in /var/nginx/blog/app/assets/stylesheets

In my nginx.conf, I write this:

location ~ ^/(assets|images|javascripts|stylesheets|system)/ {
    expires max;
    add_header Cache-Control public;
}

It seems that this is the place which is wrong! But I comment this, it still cannot find js and css. how do I config to get these files?

Upvotes: 1

Views: 1110

Answers (2)

Vladis Spirenskas
Vladis Spirenskas

Reputation: 131

You should to run RAILS_ENV=production bundle exec rake assets:precompile on remote server where you deploying.

assets:precompile rake task compressing and minimizing your assets for fast and reliable high-load production usage. Do not need to run this task on your development enviroment.

Would be better if you can show your deploy script. But most of deployment solutions like capistrano automaticaly doing this things right.

Upvotes: 2

Leo Gasparrini
Leo Gasparrini

Reputation: 171

Maybe you should put your assets in public/ folder. Do you try precompile the assets?

rake assets:precompile

Upvotes: 3

Related Questions