资产rails 3.1在预编译nginx + unicorn后未加载

时间:2012-03-22 15:44:06

标签: ruby-on-rails ruby-on-rails-3 asset-pipeline production-environment

我正在尝试在生产环境中预编译资产。但是在预编译后,应用程序找不到图像文件,javascripts文件,css文件......等。

我运行此命令:

RAILS_ENV=production rake assets:precompile

我得到了这个结果:

/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

然后我尝试重新加载页面,我看到了:

enter image description here

我正在使用nginx +独角兽。

为什么应用程序找不到资产,图片,CSS,javascript ......

编辑**

我从 application.html.erb 加载我的资产布局:

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

我在服务器{}

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

谢谢

2 个答案:

答案 0 :(得分:4)

问题已解决:D:

错误发生在nginx.conf中:

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

root到资产的路径很糟糕,正确的形式是:

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

谢谢!

答案 1 :(得分:0)

首先,

你能检查 - 清单文件和指令吗? app/assets/javascripts/application.js它应该是

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

app/assets/stylesheets/application.css

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

检查应用程序中config / environment / production.rb中的设置 应该是真的

  

config.assets.compile = true

如果您想要资产网址的摘要,请将其设为false,如果它为false。

config.assets.digest = true

很少有参考链接

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

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