为什么Rails演示应用程序会给出“未初始化的常量ExecJS :: RubyRacerRuntime :: Context :: V8”?

时间:2012-10-26 16:03:16

标签: ruby ruby-on-rails-3 ruby-on-rails-3.2

成为Rails的新手,我正在尝试启动并运行一个基本的“hello world”应用程序。特别是Agile Web Development with Rails第2章中的应用程序。加载hello world页面会导致标题中出现错误。


到目前为止,我已经完成了以下工作:

rails new demo
cd demo

gem 'therubyracer'抱怨没有可用的JavaScript运行时后,Gemfile添加了ExecJS

bundle install
rake about         # (see below)
rails generate controller Say hello goodbye
rails server

此时WEBrick启动并加载http://localhost:3000/say/hello。 WEBrick记录以下错误(也出现在浏览器中):

Started GET "/say/hello" for 127.0.0.1 at 2012-10-26 11:45:10 -0400
Connecting to database specified by database.yml
Processing by SayController#hello as HTML
  Rendered say/hello.html.erb within layouts/application (80.9ms)
Completed 500 Internal Server Error in 167ms

ActionView::Template::Error (uninitialized constant ExecJS::RubyRacerRuntime::Context::V8
  (in /home/error/work/demo/app/assets/javascripts/say.js.coffee)):
    3: <head>
    4:   <title>Demo</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___1746644185114933585_70069037653480'


  Rendered /home/error/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.7ms)
  Rendered /home/error/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.2ms)
  Rendered /home/error/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (18.7ms)
[2012-10-26 11:45:12] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

rake about返回:

About your application's environment
Ruby version              1.9.3 (x86_64-linux)
RubyGems version          1.8.24
Rack version              1.4
Rails version             3.2.8
JavaScript Runtime        therubyracer (V8)
Active Record version     3.2.8
Action Pack version       3.2.8
Active Resource version   3.2.8
Action Mailer version     3.2.8
Active Support version    3.2.8
Middleware                ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x0000000276b298>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root          /home/error/work/demo
Environment               development
Database adapter          sqlite3
Database schema version   0

工作站正在运行Fedora 17 x86_64。尽管如此,我几乎忽略了yum存储库中的ruby gem(我认为),并在我的主目录中使用gem install来获取我需要的一切。 (再一次,我想。)

对Ruby和Rails不熟悉,我很确定我错过了一些我还没有意识到的明显约定。我也不太确定我可能需要提供哪些其他信息,所以请让我知道。

1 个答案:

答案 0 :(得分:2)

请试试这个:

sudo apt-get install nodejs

ruby​​theracer和nodejs都是javascript库。这些天大多数人都在寻找nodejs。