2011-12-04 105 views
1

我是Ruby on Rails的新手。我終於成功地在ubuntu 11上安裝了rails,並創建了一個「rails new myapp」應用程序。rails生成模型:錯誤

但同時產生與模型「捆綁高管軌生成模型評論用戶:字符串USER_COMMENT:文本」我收到以下錯誤:

我毫無頭緒的可能是什麼地方出了錯。

/home/pratuat/.rvm/gems/ruby-1.9.2-p290/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 /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.9/lib/execjs.rb:5:in `' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.2.9/lib/execjs.rb:4:in `' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `require' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require' 
    from /home/pratuat/.rvm/gems/[email protected]/gems/bundler-1.0.21/lib/bundler.rb:122:in `require' 
    from /home/pratuat/Documents/rails/railsdemo/config/application.rb:7:in `' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:21:in `require' 
    from /home/pratuat/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:21:in `' 
    from script/rails:6:in `require' 
    from script/rails:6:in `'
+0

可能重複的[Rails 3.1錯誤 - 無法找到JavaScript運行時?](http://stackoverflow.com/questions/7092107/rails-3-1-error-could-not-find-a-javascript-運行時) –

回答

4

https://github.com/sstephenson/execjs

你需要從運行時的那個列表中進行選擇。我發現的最簡單的是therubyracer。將其添加到您的Gemfile中,然後執行bundle install

gem "therubyracer" 

之後,你的模型生成器應該工作。

+0

我也注意到你需要** node.js **或** gem'execjs'**安裝在Ubuntu上。 – pratuat

+0

如果你安裝node.js,你不需要爲新的應用程序做任何這樣的事情,因爲它被rails作爲你的javascript運行時獲取。 – Aras