首次运行 Ruby on Rails 时出现 execjs 错误 - “bundle install” 和 “rake about” 在我看来没有问题

首次运行 Ruby on Rails 时出现 execjs 错误 - “bundle install” 和 “rake about” 在我看来没有问题

我最近在 Centos 服务器上安装了 Ruby on Rails,作为在生产环境中安装的练习。在我的 Gemfile 中,我有以下未注释的行:

source 'https://rubygems.org'
gem 'rails', '4.0.2'
gem 'mysql2'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
gem 'execjs'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
  gem 'sdoc', require: false
end

以下是我安装的 RVM 信息:

]# rvm list

rvm rubies

=* ruby-2.0.0-p353 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

我的耙子在:

]# rake about
About your application's environment
Ruby version              2.0.0 (x86_64-linux)
RubyGems version          2.2.0
Rack version              1.5
Rails version             4.0.2
JavaScript Runtime        therubyracer (V8)
Active Record version     4.0.2
Action Pack version       4.0.2
Action Mailer version     4.0.2
Active Support version    4.0.2
Middleware                Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000004c79418>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
Application root          /var/www/html/omcw
Environment               development
Database adapter          mysql2
Database schema version   0

我正在使用《实用程序员指南》,在 Windows 上使用 DevKit 执行这些步骤,使用 webricks 效果很好,所以我认为它也应该在 Linux 上有效。我已经连接到后端的 mysql db,据我所知,它运行良好,由于链接限制,我的 database.yml 未附加,如果您想查看它,请告诉我。

到目前为止,我所做的就是创建一个新的应用程序,通过 webricks 查看时,它运行良好(这不会显示在我的 httpd 服务上 - 但我相信这是设计使然,因为根据我看到的错误,我没有为此设置路由 - 这不是我过于担心的事情)。然后我使用以下命令设置了一个应用程序:

rails generate controller Say hello goodbye

当我尝试访问页面 host:3000/say/hello 时,出现返回此错误的页面:

Sprockets::FileNotFound in Say#hello
Showing /var/www/html/omcw/app/views/layouts/application.html.erb where line #6 raised:

couldn't find file 'execjs'
  (in /var/www/html/omcw/app/assets/javascripts/application.js:13)
Extracted source (around line #6):

  <head>
    <title>Omcw</title>
    <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
  </head>
  <body>

我已经从框架跟踪中复制了输出粘贴箱

最后,我的捆绑安装列出已安装的 execjs:

]# bundle show execjs
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/execjs-2.0.2

如果我查看页面视图端口 80,我会在 Web 浏览器中看到以下内容:

Web application could not be started
Cannot execute "/usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/buildout/agents/SpawnPreparer": No such file or directory (errno=2)
Application root
/var/www/html/omcw
Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV and PASSENGER_ENV)
production
Ruby interpreter command
/usr/local/rvm/wrappers/ruby-2.0.0-p353/ruby
User and groups
Unknown
Environment variables
Unknown
Ulimits
Unknown

我的 httpd 错误日志:

App 24331 stderr: Cannot execute "/usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/buildout/agents/SpawnPreparer": No such file or directory (errno=2)
[ 2014-01-04 11:04:31.2524 3414/7f38c941e700 Pool2/Implementation.cpp:882 ]: Could not spawn process for group /var/www/html/omcw#default: An error occured while starting up the preloader.
     in 'void Passenger::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:455)
     in 'std::string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:590)
     in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
     in 'virtual Passenger::ApplicationPool2::ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:752)
     in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const Passenger::ApplicationPool2::SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned int)' (Implementation.cpp:803)

[ 2014-01-04 11:04:31.2530 3414/7f38c9e60700 agents/HelperAgent/RequestHandler.h:2065 ]: [Client 20] Cannot checkout session.
Error page:
Cannot execute "/usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.33/buildout/agents/SpawnPreparer": No such file or directory (errno=2)

我确信我在这里做错了什么,但我尝试搜索我看到的错误,我尝试过的所有方法都没有解决这个问题。我收到错误消息,指出无法找到 execjs,但我已经安装了它,这是个转移注意力的借口,还是我遗漏了什么?

我确实尝试从我的 Gemfile 中删除 execjs 提及,我希望这意味着它只会使用 therubyracer,但这也不起作用。

感谢您的帮助!如果您需要更多信息,请告诉我。

答案1

我缺少 gem ‘jquery-rails’

相关内容