新手问题 请教一下关于 rails assets precompile 问题

2forVendetta · 2013年06月03日 · 最后由 huacnlee 回复于 2013年06月03日 · 3354 次阅读

我用的 nginx+unicorn
访问网站会出现 We're sorry, but something went wrong.
我看了一下 production.log

Connecting to database specified by database.yml
Started GET "/" for 112.226.204.86 at 2013-06-03 22:24:47 +0800
Processing by DiscussionsController#index as HTML
  Rendered collection (0.0ms)
  Rendered discussions/_discussions.html.erb (0.8ms)
  Rendered discussions/index.html.erb within layouts/application (18.0ms)
Completed 500 Internal Server Error in 128ms

ActionView::Template::Error (application.css isn't precompiled):
    3: <head>
    4:   <title><%= full_title(yield(:title)) %></title>
    5:   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    6:   <%= stylesheet_link_tag    "application", :media => "all" %>
    7:   <%= stylesheet_link_tag    "home", :media => "all" %>
    8:   <%= javascript_include_tag "application" %>
    9:   <%= csrf_meta_tags %>
  app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___881267949553662586_30659220'

然后根据 stackoverflow 上说的设置了 config.assets.compile = true 重启了 unicorn 依然还是上面的情况
最后 rake assets:precompile 又报出一些错误

/usr/bin/ruby1.9.1 /usr/local/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!

  (in /var/rails/baiwale/app/assets/javascripts/application.js)
/var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:142:in `exec_runtime'
/var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
/var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
/var/lib/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
/var/lib/gems/1.9.1/gems/uglifier-2.1.0/lib/uglifier.rb:173:in `really_compile'
/var/lib/gems/1.9.1/gems/uglifier-2.1.0/lib/uglifier.rb:97:in `compile'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/compressors.rb:74:in `compress'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processing.rb:265:in `block in js_compressor='
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in `call'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in `evaluate'
/var/lib/gems/1.9.1/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/bundled_asset.rb:26:in `initialize'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `new'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `build_asset'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:19:in `block in compile'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
/var/lib/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:18:in `compile'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:56:in `internal_precompile'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.9.1 /usr/local/bin/rake ass...]
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils.rb:80:in `ruby'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `ruby'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

实在是有点晕
还有实验了 config.assets.precompile += %w( application.css ) 和 config.assets.precompile += %w( application.js ) 还是不可以 -.-!
麻烦各位帮忙看看 谢谢

部署之前需要先 rake assets:precompile 具体请详细看一下 Rails Assets Pipline 的 Guide

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册