Don't forget to...


Saturday, November 26, 2011

Rails on heroku

Just found out that the new Rails 3.1.3 can be deployed to heroku using 'heroku create --stack cedar' instead of 'heroku create'.  By doing this, the only thing you have to change in the Gemfile is delete the line 'gem sqlite3' and add the following:

group :development, :test do
  gem 'sqlite3'

group :production do
  gem 'pg'

then commit and push to heroku.

Friday, November 25, 2011

Deploying a Rails 3.1.1 app to heroku using Ruby 1.9.3 and Ubuntu 11.10

Hello friends. :P

I (FINALLY) got a Rails app working on heroku!  But it took some doing - even the basic template rails app wouldn't work on heroku!  And the getting started walkthrough on the heroku website didn't tell me what to do about the errors.  I'm still not sure if it's my OS that makes this trickier than advertised, or if it's the version of Ruby or Rails that I'm using...or maybe it's heroku's problem?  Oh well.  But here's my setup, and if you've got the same then this tutorial should work for you.  This tutorial assumes you've already setup your heroku account.

Operating System: Ubuntu 11.10
Ruby version : 1.9.3p0
Rails version : 3.1.1
Source control : Git

 First off, if you haven't already, generate a stock app, and enter its directory :

>rails new my_app
>cd my_app

Next, initialize a new Git repository, and add everything to it :

>git init
>git add .
>git commit -am "Initial commit."

now, open up the file called 'Gemfile' in a text editor, and add the following code to the very top of the file:

if RUBY_VERSION =~ /1.9/
   Encoding.default_external = Encoding::UTF_8
   Encoding.default_internal = Encoding::UTF_8

and then add the following code just underneath the word 'end' after the 'group :assets do' section :

group :production do
  gem 'pg'
  gem 'execjs'
  gem 'therubyracer'

now save the file, commit it to git, create a heroku app, push it up (and don't forget to run 'heroku rake db:migrate' if you have a database running in your app already) :

>git commit -am "updated Gemfile to work on heroku."
>heroku create
>git push heroku master

Now navigate to the url that heroku gives you, and your app should (finally) be running!  Congrats.