How to start multiple rails projects just by one command

If you do serious Rails programming, you may have multiple projects for your application. For example you may have one project for an API and another for a web UI. You might also use some background processing like sidekiq etc. Every time you need to launch these services on a development environment, you have to launch all projects in separate consoles manually.

Fortunately there is a better way to do it. By using a gem ‘subcontractor’ together with ‘foreman’ gem, you can define all the projects and services that you want to launch in the ‘Procfile’, for example:

Then you can launch all the projects and services just by one command:

foreman start

How to run Jasmine javascript tests in CI server (Ruby)

Jasmine.js is a great testing framework for Javascript. However running tests in Continuous Integration (CI) server is somehow problematic because the server usually does not have a screen where to open a browser.

The solution is to use Xvfb and headless gem:

Headless is the Ruby interface for Xvfb. It allows you to create a headless display straight from Ruby code, hiding some low-level action. It can also capture images and video from the virtual framebuffer.

To run your tests in CI server, do the following steps:

  1. Install xvfb
    $ sudo apt-get install xvfb
  2. Install firefox
    $ sudo apt-get install firefox
  3. Install headless gem
    $ gem install headless
    add it to Gemfile
    gem ‘headless’
    and run
    $ bundle install
  4. create rake task for headless jasmine runner (
  5. run or add rake task to your build configuration
    rake jasmine:ci:headless

Mongoid and assets problem on Ruby on Rails 3.2

I was doing my first Ruby on Rails application with MongoDB (via Mongoid gem). When I deployed the application to a production server, assets were compiled correctly but all javascript and css links were still pointing to stylesheets and javascripts folders, like

<link href=”/stylesheets/application.css” media=”screen” rel=”stylesheet” type=”text/css” />

I checked capistrano and server configurations, but nothing were wrong there. Finally I figured out what was causing the problem. I have not required “sprockets/railtie” in the config/application.rb

In the Mongoid documentation especially in ‘Configuration’ section is ‘Getting Rid of Active Record’ subsection which says:

Open myapp/config/application.rb and near the top, remove the line require "rails/all" and add the following lines so you end up with this:

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
# require "sprockets/railtie" # Uncomment this line for Rails 3.1+

In a rush I only saw number 3.1 and thought it is okay to leave it as uncommented. Current Rails version is 3.2.8 so should that line be uncommented as default on Mongoid documentation?