Browse files

Add therubyracer as a minimal JavaScript runtime

  • Loading branch information...
1 parent fb840bf commit a64742c2b7b3bf801375101d89f944f19c985c5a @mike-burns mike-burns committed Jun 29, 2012
Showing with 1 addition and 0 deletions.
  1. +1 −0 templates/Gemfile_additions
@@ -5,6 +5,7 @@ gem 'formtastic'
gem 'flutie'
gem 'bourbon'
gem 'airbrake'
+gem 'therubyracer'
group :development do
gem 'foreman'

5 comments on commit a64742c


croaky replied Aug 3, 2012

@mike-burns, can you provide more details about this commit? I haven't had to do this on any projects and think it can be removed from Suspenders.


mike-burns replied Aug 3, 2012

You need a JS runtime to run Rails. Perhaps you have one installed globally?

~% suspenders foo
      create  Rakefile
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      create  app/assets/stylesheets/application.css
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  app/mailers/.gitkeep
      create  app/models/.gitkeep
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/initializers/wrap_parameters.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  lib/assets
      create  lib/assets/.gitkeep
      create  log
      create  log/.gitkeep
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  script
      create  script/rails
      create  tmp/cache
      create  tmp/cache/assets
      create  vendor/assets/javascripts
      create  vendor/assets/javascripts/.gitkeep
      create  vendor/assets/stylesheets
      create  vendor/assets/stylesheets/.gitkeep
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
      remove  public/index.html
      remove  app/assets/images/rails.png
Setting up the development environment
      create  spec/support/factory_girl.rb
Setting up the staging environment
         run  cp config/environments/production.rb config/environments/staging.rb from "."
Creating suspenders views
      create  app/views/application
      create  app/views/application/_flashes.html.erb
      create  app/views/application/_javascript.html.erb
       force  app/views/layouts/application.html.erb
Pulling in some common javascripts
       exist  app/assets/javascripts
      create  app/assets/javascripts/prefilled_input.js
Add jQuery ui to the standard application.js
      insert  app/assets/javascripts/application.js
      insert  Gemfile
      insert  Gemfile
         run  bundle install
Fetching gem metadata from
Using rake ( 
Using i18n (0.6.0) 
Using multi_json (1.3.6) 
Using activesupport (3.2.6) 
Using builder (3.0.0) 
Using activemodel (3.2.6) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.6) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.6) 
Using arel (3.0.2) 
Using tzinfo (0.3.33) 
Using activerecord (3.2.6) 
Using activeresource (3.2.6) 
Installing addressable (2.3.2) 
Installing airbrake (3.1.2) 
Using sass (3.1.20) 
Using bourbon (2.1.1) 
Using metaclass (0.0.1) 
Using mocha (0.10.5) 
Using bourne (1.1.2) 
Using bundler (1.1.3) 
Using nokogiri (1.5.5) 
Installing ffi (1.1.3) with native extensions 
Using childprocess (0.3.4) 
Installing libwebsocket (0.1.5) 
Using rubyzip (0.9.9) 
Using selenium-webdriver (2.25.0) 
Using xpath (0.1.4) 
Using capybara (1.1.2) 
Using json (1.7.4) 
Using capybara-webkit (0.11.0) 
Using rack-ssl (1.3.2) 
Using rdoc (3.12) 
Using thor (0.15.4) 
Using railties (3.2.6) 
Using diesel (0.1.5) 
Using rails (3.2.6) 
Using clearance (0.16.3) 
Using cocaine (0.2.1) 
Using coffee-script-source (1.3.3) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using coffee-rails (3.2.2) 
Using diff-lcs (1.1.3) 
Using gherkin (2.11.1) 
Using cucumber (1.2.1) 
Using cucumber-rails (1.3.0) 
Using daemons (1.1.8) 
Using database_cleaner (0.8.0) 
Using eventmachine (0.12.10) 
Installing factory_girl (3.6.1) 
Installing factory_girl_rails (3.6.0) 
Using flutie (1.3.3) 
Installing foreman (0.53.0) 
Using formtastic (2.2.1) 
Using high_voltage (1.1.1) 
Using jquery-rails (2.0.2) 
Installing launchy (2.1.1) 
Using libv8 ( 
Installing newrelic_rpm (3.4.1) 
Using paperclip (3.1.4) 
Using pg (0.14.0) 
Using rspec-core (2.9.0) 
Using rspec-expectations (2.9.1) 
Using rspec-mocks (2.9.0) 
Using rspec (2.9.0) 
Using rspec-rails (2.9.0) 
Using sass-rails (3.2.5) 
Using sham_rack (1.3.4) 
Using shoulda-matchers (1.2.0) 
Using therubyracer (0.10.1) 
Installing thin (1.4.1) with native extensions 
Installing timecop (0.4.4) 
Using uglifier (1.2.7) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from newrelic_rpm:


Developer Mode is now a Rack middleware.

Developer Mode is no longer available in Rails 2.1 and earlier.
However, starting in version 2.12 you can use Developer Mode in any
Rack based framework, in addition to Rails.  To install developer mode
in a non-Rails application, just add NewRelic::Rack::DeveloperMode to
your middleware stack.

If you are using JRuby, we recommend using at least version 1.4 or 
later because of issues with the implementation of the timeout library.

Refer to the file for more information.

Please see
for a complete description of the features and enhancements available
in version 3.4 of the Ruby Agent.

Setting up database
       force  config/database.yml
         run  bundle exec rake db:create
Configuring app
      insert  config/application.rb
      insert  config/environments/development.rb
      insert  config/environments/test.rb
      insert  config/environments/staging.rb
      insert  config/environments/production.rb
    generate  rspec:install
      create  .rspec
       exist  spec
      create  spec/spec_helper.rb
    generate  cucumber:install
      create  config/cucumber.yml
      create  script/cucumber
       chmod  script/cucumber
      create  features/step_definitions
      create  features/support
      create  features/support/env.rb
       exist  lib/tasks
      create  lib/tasks/cucumber.rake
        gsub  config/database.yml
        gsub  config/database.yml
       force  config/database.yml
      insert  features/support/env.rb
      insert  config/cucumber.yml
      create  app/validators/email_validator.rb
      append  Rakefile
Set up stylesheets
      create  app/assets/stylesheets/application.css.scss
      remove  app/assets/stylesheets/application.css
      append  app/assets/stylesheets/application.css.scss
      create  app/assets/stylesheets/_screen.scss
Copying miscellaneous support files
      create  config/initializers/errors.rb
      create  config/initializers/time_formats.rb
      create  Procfile
Customizing the 500/404/422 pages
      insert  public/500.html
      insert  public/404.html
      insert  public/422.html
Setting up a root route
       route  root :to => 'Clearance::Sessions#new'
Initializing git
      append  .gitignore
       exist  app/models
   identical  app/models/.gitkeep
       exist  app/assets/images
      create  app/assets/images/.gitkeep
      create  app/views/pages
      create  app/views/pages/.gitkeep
      create  db/migrate
      create  db/migrate/.gitkeep
       exist  log
   identical  log/.gitkeep
       exist  spec/support
      create  spec/support/.gitkeep
      create  spec/lib
      create  spec/lib/.gitkeep
      create  spec/models
      create  spec/models/.gitkeep
      create  spec/views
      create  spec/views/.gitkeep
      create  spec/controllers
      create  spec/controllers/.gitkeep
      create  spec/helpers
      create  spec/helpers/.gitkeep
      create  spec/support/matchers
      create  spec/support/matchers/.gitkeep
      create  spec/support/mixins
      create  spec/support/mixins/.gitkeep
      create  spec/support/shared_examples
      create  spec/support/shared_examples/.gitkeep
         run  git init from "."
Initialized empty Git repository in /home/mike/foo/.git/
Congratulations! You just pulled our suspenders.
Remember to run 'rails generate airbrake' with your API key.
    generate  clearance:install
      create  db/migrate/20120803114837_create_diesel_clearance_users.rb
      create  config/initializers/clearance.rb
      insert  app/controllers/application_controller.rb
      create  app/models/user.rb
      create  spec/factories/clearance.rb


Next steps:

1. Configure the mailer to create full URLs in emails:

     # config/environments/{development,test}.rb
     config.action_mailer.default_url_options = { :host => 'localhost:3000' }

   In production it should be your app's domain name.

2. Display flashes. For example, in your application layout:

    <% flash.each do |key, value| -%>
      <div class="flash <%= key %>"><%= value %></div>
    <% end -%>

3. Migrate:

     rake db:migrate

    generate  clearance:features
      create  features/clearance/visitor_resets_password.feature
      create  features/clearance/visitor_signs_in.feature
      create  features/clearance/visitor_signs_out.feature
      create  features/clearance/visitor_signs_up.feature
      create  features/step_definitions/clearance/clearance_steps.rb
      create  spec/support/clearance.rb
      insert  app/models/user.rb
~% ./foo                              
app/       db/        Gemfile       log/      Rakefile   spec/
config/    doc/       Gemfile.lock  Procfile  tmp/  features/  lib/          public/   script/    vendor/
~/foo% sed -e '/therubyracer/d' -i Gemfile
~/foo% ./script/rails s
/home/mike/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `each'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler/runtime.rb:66:in `block in require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
    from /home/mike/foo/config/application.rb:13:in `<top (required)>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands.rb:53:in `require'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands.rb:50:in `tap'
    from /home/mike/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands.rb:50:in `<top (required)>'
    from ./script/rails:6:in `require'
    from ./script/rails:6:in `<main>'

joshuaclayton replied Aug 3, 2012

@mike-burns @croaky I ran into the exact same issue a couple of days ago. Digging around execjs helped me realize there's no actual dependency on a runtime, but it'll raise if it can't find one. If one is present on your system, everything looks good, but for someone starting fresh without having installed a runtime first, this is a really big issue.

Additionally, this came up during my Intro to Test-Driven Rails workshop, and I was thrown off, much like you are Dan, because I figured it just worked on everyone's machine. The exception message helps, but I think it's nice to provide one so developers can get up and running, with or without a JS runtime installed.


adarsh replied Aug 3, 2012


croaky replied Aug 3, 2012

The plain old rails new command includes the following gems in its Gemfile:


therubyracer is in the Gemfile, but commented out, explained here:

Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an execjs error. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to Gemfile in apps generated under JRuby. You can investigate about all the supported runtimes at ExecJS.

So, suspended apps end up with:

# See for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'therubyracer'

Since Rails has it commented out by default and the commented out version also includes a link in the comment to more information, I'm going to remove therubyracer in Suspenders.

Please sign in to comment.