【问题标题】:rails s command not workingrails的命令不起作用
【发布时间】:2014-06-21 00:14:46
【问题描述】:

您好,我正在 Windows 8 机器上使用 ruby​​ on rails,我很难在我的机器上设置 ruby​​ 2.1。当我运行 rails s 时出现以下错误:

C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.2.0/lib/execjs/run
times.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://gi
thub.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUn
available)
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.2.0/l
ib/execjs.rb:5:in `<module:ExecJS>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/execjs-2.2.0/l
ib/execjs.rb:4:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/uglifier-2.5.1
/lib/uglifier.rb:3:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/uglifier-2.5.1
/lib/uglifier.rb:3:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler/runtime.rb:76:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler/runtime.rb:76:in `block (2 levels) in require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler/runtime.rb:72:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler/runtime.rb:72:in `block in require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler/runtime.rb:61:in `each'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler/runtime.rb:61:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/
lib/bundler.rb:132:in `require'
        from C:/HandCo-op/HandCo-op/config/application.rb:7:in `<top (required)>
'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.2
.rc1/lib/rails/commands/commands_tasks.rb:79:in `require'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.2
.rc1/lib/rails/commands/commands_tasks.rb:79:in `block in server'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.2
.rc1/lib/rails/commands/commands_tasks.rb:76:in `tap'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.2
.rc1/lib/rails/commands/commands_tasks.rb:76:in `server'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.2
.rc1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.1.2
.rc1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

我认为这是因为我需要 ruby​​ 2.1 并且安装的版本是 2.0。有谁知道我应该怎么做才能修复这些错误?非常感谢任何知道为什么我不能运行 rails s 的人。

【问题讨论】:

  • Protip,堆栈跟踪通常会给出原因的线索,或者至少给出问题所在的线索。虽然第一行非常神秘,但下一行指向github.com/sstephenson/execjs 以获取更多信息。

标签: ruby-on-rails ruby


【解决方案1】:

这很有趣,我刚刚使用 ruby​​ 2.1 初始化了一个新的 rails 4 项目,当忘记更新 Gemfile 时,几分钟前我收到了确切的错误消息。

更新您的 Gemfile 取消注释 gem 'therubyracer' 行,如下所示:

# Gemfile
gem 'therubyracer',  platforms: :ruby

更新Gemfile 后运行bundle 命令。

错误消息是因为您没有安装运行时。

更新:Windows 上的选项

我已经在 Windows 7+ x64 架构上成功安装和使用 closure-compiler gem。我的开发箱不时从 linux 切换到 windows,所以下面是我的 Gemfile 设置:

# Gemfile

gem 'therubyracer', :platforms => :ruby
gem 'execjs', :platforms => :ruby

gem 'closure-compiler'

并通过更新以下行来更新config/environments/ 中的任一环境或config/application.rb 中的应用程序范围的配置:

config.assets.js_compressor = :closure

请参阅Customizing the Pipeline,了解 RailsGuide 的更多信息。

【讨论】:

  • 我试过了,得到了同样的错误。但是,在取消注释该行并运行 bundle install 后,我没有看到正在安装 ruby​​racer。
  • @ZachyBear,请查看更新。希望有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-16
  • 2015-08-26
  • 1970-01-01
  • 1970-01-01
  • 2020-06-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多