execjs error when upgrade rails from 3.0.x to 3.1.0 [problem solved]

来源:互联网 发布:淘宝ebay代购靠谱吗 编辑:程序博客网 时间:2024/05/21 22:30

When I upgrade the rails from 3.0.x to 3.1.0, the old app can't work. Even the new one will give the error like:

/var/lib/gems/1.9.1/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)from /var/lib/gems/1.9.1/gems/execjs-1.2.9/lib/execjs.rb:5:in `<module:ExecJS>'from /var/lib/gems/1.9.1/gems/execjs-1.2.9/lib/execjs.rb:4:in `<top (required)>'from /var/lib/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'from /var/lib/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'from /var/lib/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'from /var/lib/gems/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'from /var/lib/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `require'from /var/lib/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `<top (required)>'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `block (2 levels) in require'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `block in require'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'from /var/lib/gems/1.9.1/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'from /media/ror/tmp2/config/application.rb:7:in `<top (required)>'from /var/lib/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:52:in `require'from /var/lib/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:52:in `block in <top (required)>'from /var/lib/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'from /var/lib/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:49:in `<top (required)>'from script/rails:6:in `require'from script/rails:6:in `<main>'

To solve the problem, we need to do following steps:

sudo gem install execjs therubyracer

And add the following line in the Gemfile for the new RoR applications:

gem 'therubyracer'

In the 3.1.0, the default place for holding javascript is changed from 3.0.x. The old app can't find the right javascript under the new framework. Need to move the old js files to the new place.

Please refer to: http://stackoverflow.com/questions/6282307/rails-3-1-execjs-and-could-not-find-a-javascript-runtime


原创粉丝点击