How to use Git and Heroku for rapid Ruby on Rails 3 Deployment

July 9th, 2011

Why Heroku?

My existing Hostmonster account did not support Rails 3.  As Rails 3 is the only version of Rails with which I am familiar, I decided to try deploying in the cloud instead, and Heroku was the first name on Google.  It’s free to get started (pricing kicks in when you want more of anything), and incredibly fast to deploy, even from Windows. Engine Yard seems to be another popular choice that I’ll take a look at later.


Why Git?

Heroku depends on Git, Aptana requires it (and installs its own version if you don’t have it), and Agile Development with Rails assumes the use of Git throughout.  Git is clearly the Software Configuration Management (SCM) system of choice for a substantial segment of the RoR community – and that’s good enough for me.


Installing Git, and loading source onto Git

I installed Git when I installed Aptana Studio 3 – it is a prerequisite, and a version is included in the Aptana binary.  I am not sure if there are pros / cons to using this included version versus installing from GitHub directly, but it has worked well for me thus far.  If you still need to install Git, you can follow these instructions to install Git for Windows.

You’ll need to have a Git username and password set up – the example below is for user Adam Wible.  You can do this by modifying your .gitconfig file, which typically goes in your home directory.  The easier way is to do this automatically via the following commands in the Aptana shell:

$ git config –global “Adam Wible”

$ git config –global “”

After this is set up, you should generate a public key, as this is necessary to publish code to the web via Git / Heroku:

$ ssh-keygen -t rsa -c “”

More information here:

Press enter when it asks for the file in which to save the key (accept the default, in your home directory), and then enter a passphrase, twice.

Create an account on GitHub, remember the username you created.  It will also generate an API key based on your password, which you can access in your account admin section.

Add public key to your GitHub account by pasting in the contents of:


Then test with:


This should give you the following message:

Hi [username]!  You’ve successfully authenticated, but GitHub does not provide shell access.  Connection to closed.

Navigate to the directory of the application you are deploying.  Continue the Git configuration with the following shell commands based on the username and token you just created on GitHub.  Again, the example below is for user Adam Wible:

$ git config –global github.user adamwible

$ git config — global github.token your_github_token

$ git init

$ git add .

$ git commit -m ‘first commit’

$ git remote add origin

$ git push -u origin master

With this you are ready to go – done, Adam Wible.


How to install Heroku

Make a new account online, confirm your email address

Install the heroku gem:

$ gem install heroku

$ heroku create

Login with the Heroku username and password you just created.  Generate a public key (heroku couldn’t do it for me, so I did the SSH thing), make a passphrase, and you’re ready to go. Done – Adam Wible.


How to deploy using Heroku

heroku rake db:migrate (different than rake db:migrate)

heroku rake db:seed

Note that there is no reason to mess with the production database settings in the Gemfile and config/database.yml file because these are ignored by Heroku.  Heroku will put you on a shared PostgreSQL database, for your own good.

If you want to rename (via the Heroku website interface), you’ll need to replace the existing heroku remote with an updated one:

$ git remote rm heroku
$ git remote add heroku

And that’s it – Adam Wible.

The deployed test site is available at


Replacing Prototype (RJS) with JQuery on Rails 3 for Windows

April 22nd, 2011

When I tried to replace Rails’ native Prototype (RJS) library with the popular client-side JavaScript library JQuery, I ran into the following SSH error, apparently caused by Rails not knowing where certificates are kept on Windows:

fetching  jQuery UJS adapter (github HEAD)

c:/Ruby/192/lib/ruby/1.9.1/net/http.rb:678:in `connect’: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

While this is a known issue that has apparently been closed, none of the suggestions at the following thread worked for me:

Here’s what did work for me.  Find Ruby’s open-uri.rb file.  For me this was at:


On line 288, you’ll see:

http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER

Comment this line temporarily, and copy it to the line below with the following modification:

http.verify_mode = OpenSSL::SSL::VERIFY_NONE

This is a temporary hack to eliminate the SSH error message, allowing us to install JQuery.  Then we can try the JQuery install again:

$ rails generate jquery:install –ui –force

remove  public/javascripts/controls.js

remove  public/javascripts/dragdrop.js

remove  public/javascripts/effects.js

remove  public/javascripts/prototype.js

fetching  jQuery (1.5)

identical  public/javascripts/jquery.js

identical  public/javascripts/jquery.min.js

fetching  jQuery UI (latest 1.x release)

identical  public/javascripts/jquery-ui.js

identical  public/javascripts/jquery-ui.min.js

fetching  jQuery UJS adapter (github HEAD)

force  public/javascripts/rails.js

Finally, return to open-uri.rb, comment or remove the line we added, and uncomment the original line 288.

And that’s all there is to it.  Adam Wible

How to learn Rails 3, quickly

April 12th, 2011

Ruby on Rails is a strange new world.  The whole “convention over configuration” thing makes sense, but the conventions can be surprising – especially when things are magically pluralized and de/re capitalized, and commands interspersed with proper names are magically parsed by shovel, or rake, or some tool that is equally mysterious.  I wouldn’t presume to shed any light here, but I do recommend the following book:

Agile Web Development with Rails, 4th Ed


I think this is a great book for several reasons:

  • If you’ve done any programming before, you can get by without really knowing Ruby.  It’s very readable, and this is an easy / painless way to pick up the fundamentals of Ruby along the way.  You can always follow it up by skimming Book of Ruby to confirm / deny what you’ve deduced
  • Little idle chatter – you jump right in, way over your head, and build a functioning web application.  Working through the demo app (“depot”) is fun and very real.  It is quite puzzling without being so overwhelming that you want to quit.
  • This is based on Rails 3 – the latest release, substantially refactored.  Best place to start, as old versions will presumably only be of interest to those maintaining old code
  • There are exercises that go beyond the tutorial – just when your eyes glaze over and you become a robot typing in the examples, you’re forced to think for yourself, confront the fact that you didn’t really absorb anything in the preceding chapter, and then learn it properly.

More to come on the first deployment (of the “depot” example).

How to install Ruby on Rails 3 with MySQL on Windows 7, really

March 20th, 2011

The Ruby on Rails (RoR) installation tutorials for Windows that already exist are listed at the end of this post.  I found the need to combine them, and at times to deviate from them to get Ruby on Rails 3 installed on Windows 7 and get it working with MySQL.  I have also configured the Aptana 3 integrated development environment (IDE).  I am qualified to discuss this process only insofar as it worked for me, but decided that consolidating this information in one place may be helpful.


1) Download the Ruby Windows Installer here (at writing, rubyinstaller-1.9.2-p180.exe)

Run this file and install Ruby to a directory of your choice.  I chose C:\Ruby.  Make sure to tell the installer to add Ruby to the Windows System PATH in order to run Ruby from any directory.

Open a Windows Command Prompt (Start > Run > cmd) and using the following command to see the version number and confirm Ruby is functional:

c:\> ruby -v

ruby 1.9.2p180 <2011-02-18> [i386-mingw32]


2) RubyGems is included with Ruby 1.9.2, so let’s just confirm it is working

RubyGems is Ruby’s standard package manager, and we’ll use it to install Rails.  First, check the version

c:\> gem -v


Next, we can update RubyGems to ensure this is the latest version:

c:\>gem update –system

Latest version currently installed.  Aborting


3) Install Rails 3 via RubyGems

From the Command Prompt, run the following line:

c:\>gem install rails

You can also check the version:

c:\>rails -v

Rails 3.0.5

Done – Adam Wible


SQLite3 is the default database client for Ruby on Rails.  We will switch this over to MySQL in the next step, but for now, let’s set up SQLite3 to ensure we have a functional default (because I don’t know how to change it).

1) Download SQLite3 here.  Scroll down to “Precompiled binaries for Windows.” You will need BOTH the command line shell (at writing, and the DLL (

2) Unzip the command line shell zip and double-click sqlite3.exe to install

3) Unzip the DLL zip and copy both files, sqlite3.def and sqlite3.dll, into Ruby’s bin folder.  For me this was at:


4) Install the SQLite3 gem:

C:\Ruby\>gem install sqlite3-ruby

Done – Adam Wible


1) Download MySQL Community Server here (at writing, mysql-5.5.10-win32.msi).  Don’t monkey around with 64-bit.

2) Run the MySQL installation wizard.  It is straightforward.  Standard configuration, install as a windows service called “MySQL”, and why not include the bin directory in Windows Path?  Under “Modify Security Settings,” enter a root database password and remember this as you will need to update your database.yml files with this password.

3) In the MySQL install directory, find the libmysql.dll file.  For me this was at:

C:\Program Files (x86)\MySQL\MySQL Server 5.5\lib\libmysql.dll

Copy this file into the Ruby bin directory (same place you copied the SQLite3 DLL).

4) Install the MySQL gem:

C:\Ruby\>gem install mysql

Done – Adam Wible


Now we can test to see if our RoR installation is working.

1) From a Command Prompt, create a new test project.  If you want to use SQLite3 for the project, then stick with the default:

C:\Ruby\192\>rails new testproject

However, if you want to use MySQL, you’ll need to specify that on project creation:

C:\Ruby\192\>rails new testproject -d mysql

Either way, this should produce a lot of lines “created xxx” etc.

2) The specifying MySQL vs. sticking with the SQLite3 default will impact two files in the newly created project directory.

C:\Ruby\testproject\config\database.yml: you’ll need to edit this file to include the root database password you set up when installing MySQL.  By default, the password is blank, which will produce errors if a root password has been set.

C:\Ruby\testproject\Gemfile: this will either show gem ‘sqlite3’ or gem ‘mysql2’

3) Navigate to the newly created project folder.  Let’s generate a scaffold – this will produce a database driven web application in no time.

C:\Ruby\testproject\>rails generate scaffold user name:string bio:text email:string

C:\Ruby\testproject\>rake db:create

C:\Ruby\testproject\>rake db:migrate

C:\Ruby\testproject\>rails server

These commands create a scaffold called “user” and sets up a database with the appropriate structure.  The final command starts WEBrick, the built-in webserver.

4) Without closing the command prompt, open a browser to:


Confirm that this works for you, then you can shut down the web server with CNTRL-C.

You can continue with a more detailed tutorial here, but hopefully this has provided proof of concept.  Note that this tutorial references older versions of commands that no longer work in places (i.e., ruby script/generate has been replaced by rails generate, and the reference to app/views/posts/new.html.erb should actually be app/views/posts/_form.html.erb)

Done – Adam Wible


If you would like to take this further and work in an integrated environment with a file tree browser, shell, and syntax coloring etc, you can install Aptana Studio 3.  I’m sure many other IDE’s (like Netbeans) will also work – I arbitrarily selected this one.

1) Download the Aptana Studio 3 Beta here.  This IDE supports Ruby, Rails, PHP, and Python, as well as HTML5, CSS3 and JavaScript.

2) Note that Aptana requires Java JDK to be installed.  Prerequisites and getting started information here.

3) If you create a project through Aptana, ensure that you place it in the folder where all of your rails projects to go (may be different than the default in Aptana).

4) If you create a project through Aptana, SQLite3 will be used as the default database.  To manually change this over to MySQL, swap out projectfolder\config\database.yml for one created previously for a MySQL-based project, and also update projectfolder\Gemfile to reflect gem ‘mysql2’ instead of gem ‘sqlite3’

Done – Adam Wible