11

我一直在尝试让 RoR 与Passenger 和 Nginx 一起工作。伙计,这是一次冒险。我终于让服务器运行起来,它正在托管一个测试站点,好吧。我遇到了资产错误。我无法使用bundle exec rake assets:precompile. 以下是使用 --trace 的结果:

$ bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/pstachof/.rvm/rubies/ruby-1.9.3-head/bin/ruby /Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
TypeError: 'undefined' is not a function (evaluating 'define.globalDomain.require.bind(define.globalDomain)')
  (in /Users/pstachof/.webserver/sites/stachtest1/app/assets/javascripts/application.js)
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:68:in `extract_result'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/uglifier-2.0.1/lib/uglifier.rb:167:in `really_compile'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/uglifier-2.0.1/lib/uglifier.rb:95:in `compile'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/compressors.rb:74:in `compress'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/processing.rb:265:in `block in js_compressor='
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in `call'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/processor.rb:29:in `evaluate'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/bundled_asset.rb:26:in `initialize'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `new'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `build_asset'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:19:in `block in compile'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:18:in `compile'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/assets.rake:56:in `internal_precompile'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/pstachof/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/pstachof/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/bin/rake:23:in `load'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile:primary
rake aborted!
Command failed with status (1): [/Users/pstachof/.rvm/rubies/ruby-1.9.3-hea...]
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `sh'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `sh'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/file_utils.rb:80:in `ruby'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/file_utils_ext.rb:37:in `ruby'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.2.13/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/pstachof/.rvm/rubies/ruby-1.9.3-head/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/bin/rake:23:in `load'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head@global/bin/rake:23:in `<main>'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/bin/ruby_noexec_wrapper:14:in `eval'
/Users/pstachof/.rvm/gems/ruby-1.9.3-head/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile

如果我设置config.assets.compile = trueconfig/environments/production.rb重新启动服务器重新加载站点,我会在 production.log 中收到以下内容

Connecting to database specified by database.yml
Started GET "/" for 98.156.89.130 at 2013-04-23 22:45:35 -0500
Processing by HomeController#welcome as HTML
  Rendered home/welcome.html.erb within layouts/application (10.7ms)
Completed 500 Internal Server Error in 77ms

ActionView::Template::Error (application.js isn't precompiled):
    3: <head>
    4:   <title>Stachtest1</title>
    5:   <%= stylesheet_link_tag    "application", :media => "all" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8: </head>
    9: <body>
  app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__451492169_16346550'

如果我从 assets/javascript 目录中删除 application.js 文件(我根本没有修改)并编译一切顺利。我还尝试使用assets/javascript 目录中的文件进行编译,但删除了所有文本,但仍然失败。

我正在使用 rails 3.2.13、ruby 1.9.3 并且在本地安装了以下 gem

*** LOCAL GEMS ***

actionmailer (3.2.13)
actionpack (3.2.13)
activemodel (3.2.13)
activerecord (3.2.13)
activeresource (3.2.13)
activesupport (3.2.13)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.4)
bundler (1.3.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.6.2)
daemon_controller (1.1.2)
erubis (2.7.0)
execjs (1.4.0)
fastthread (1.0.7)
hike (1.2.2)
i18n (0.6.1)
io-console (0.3)
journey (1.0.4)
jquery-rails (2.2.1)
json (1.7.7, 1.5.5)
mail (2.5.3)
mime-types (1.23)
minitest (2.5.1)
multi_json (1.7.2)
passenger (3.0.19)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack-ssl (1.3.3)
rack-test (0.6.2)
rails (3.2.13)
railties (3.2.13)
rake (10.0.4, 0.9.2.2)
rdoc (3.12.2, 3.9.5)
rubygems-bundler (1.1.1)
rvm (1.11.3.7)
sass (3.2.8)
sass-rails (3.2.6)
sprockets (2.2.2)
sqlite3 (1.3.7)
thor (0.18.1)
tilt (1.3.7)
treetop (1.4.12)
tzinfo (0.3.37)
uglifier (2.0.1)

这是 application.js 文件

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree

当我继续使用这个设置时,我发现虽然它编译了 assets/javascript 目录中没有 application.js 文件的资产,并且看起来 css 正在正确编译,但刷新后它没有显示在网页上服务器和站点。如果我将样式直接放在网页中,它将按应有的方式呈现。

以下是相关文件:application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Stachtest1</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= csrf_meta_tags %>
</head>
<body>
    <div id="content">
        Does this work...
    </div>

    <%= yield %>

    <div style="border: 1px solid #000;">
        This is a test to see about some styles
    </div>
</body>
</html>

资产/样式表/application.css

.content
{
    border: 1px solid #999;
    padding: 5px;
}

公共/应用程序.css

.content{border:1px solid #999;padding:5px}

我不确定这是否是一个单独的问题,如果可以,我可以将其拉出但想添加它以防万一。

我的想法已经走到了尽头。任何想法或建议将不胜感激。如果我遗漏任何信息,请告诉我,我可以尽我所能填补空白。

谢谢你,帕特里克

4

3 回答 3

1

尝试:

//= require_tree .

代替

//= require_tree

以点结尾。就像在指南中一样:http: //guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

于 2016-01-27T23:02:21.193 回答
0

在旧的已部署应用程序上更新 gem 后,我看到了同样的错误。我把它缩小到 uglifier,从 1.3.0 升级到 2.0.1。根据其自述文件,它需要一个 JS 解释器:

确保您的环境具有 ExecJS 支持的 JavaScript 解释器。安装 therubyracer gem 是一个安全的选择,并且在 PATH 中使用节点也可以。

但这不是一个硬依赖,所以它没有被捆绑器捕获。我还不想继续这样做,我在 Gemfile 中将 uglifier 切换回 1.3.0:

  gem 'uglifier', '1.3.0'

一切都很好。

于 2013-05-02T20:31:55.363 回答
-1

检查删除以下行表单 application.js

//= require_tree

require_tree递归加载 app/javascripts 目录中的所有文件

如果可行,则 app/assets/javascripts 目录中的其中一个 javascript 文件存在一些问题

检查目录中的所有文件或

在 application.js 中一一要求文件

//= require js_file_name
于 2013-04-24T06:02:16.767 回答