Wednesday, 12 February 2014

I was following this guide: https://devcenter.heroku.com/articles/getting-started-with-rails4

To get rails and heroku working.

But when I got to:

$ rails generate controller welcome

I got an error:

/home/tims/.rvm/gems/ruby-2.1.0/gems/execjs-2.0.2/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable) from /home/tims/.rvm/gems/ruby-2.1.0/gems/execjs-2.0.2/lib/execjs.rb:5:in `' from /home/tims/.rvm/gems/ruby-2.1.0/gems/execjs-2.0.2/lib/execjs.rb:4:in `' from /home/tims/.rvm/gems/ruby-2.1.0/gems/uglifier-2.4.0/lib/uglifier.rb:3:in `require' from /home/tims/.rvm/gems/ruby-2.1.0/gems/uglifier-2.4.0/lib/uglifier.rb:3:in `' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in `require' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in `each' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:72:in `block in require' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `each' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler/runtime.rb:61:in `require' from /home/tims/.rvm/gems/ruby-2.1.0@global/gems/bundler-1.5.3/lib/bundler.rb:131:in `require' from /home/tims/ruby/hsfeb/config/application.rb:7:in `' from /home/tims/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:43:in `require' from /home/tims/.rvm/gems/ruby-2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:43:in `' from bin/rails:4:in `require' from bin/rails:4:in `'

I fixed this by installing therubyracer gem:

gem install therubyracer

And then by uncommenting the therubyracer line in the project's Gemfile.

(Thanks to http://guides.rubyonrails.org/getting_started.html - "Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it.")