I’ve been playing with Ruby on Rails for the past couple of weeks. It’s a very cool web development framework, and it makes things that used to be difficult, much easier (I hope). I wanted to get to know RoR because it is invented by those clever 37 signals people who made Basecamp (one of my favourite project management apps).
So I bought a book: Agile Web Development with Rails (4th edition) and started to create my first rails app on my laptop. Everything was going beautifully until I started thinking about unleashing my (admittedly fairly feeble) app onto the public. It turns out that deploying a rails app is a lot harder than producing the app itself.
In a previous life I crafted asp.net web apps for fun. Deployment essentially involved dropping a load of application files into the correct IIS directory, and browsing to the app. Not so with RoR. As it proved so difficult to deploy a hello world app, I thought I’d recap on the steps. Who knows, I might need them again sometime.
- I started by installing Ruby, Rails, Bundler, Git and some other stuff too via the fabulous RailsInstaller. This gets you up and running with a development environment in a couple of mouse clicks. Sweet.
- Next I stumbled across an excellent article: HOWTO install Ruby on Rails on Windows and deploy to Heroku by Dominic Sayers
- I followed Dominic’s steps through from 3 – 14.
- I discovered that for step 15, I have to press Ctrl-Pause/break to stop the local webserver, rather than Ctrl-C.
- I followed steps 15 – 20, all good.
- When I ran step 21, I received errors in the output however running the heroku open command resulted in the standard welcome aboard rails screen being displayed.
- I then created the simple hello world app by running: rails generate controller Say hello goodbye
- This meant that browsing to http://localhost:3000/say/hello/ resulted in ‘Say#hello Find me in app/views/say/hello.html.erb‘ being displayed. However when I ran:
git add .
git commit -m “second commit”
git push heroku
to try and push hello world to Heroku, and then browsed to my app URL http://furious-sunrise-9610.herokuapp.com/say/hello/ I found a dreaded ‘Oh dear something went wrong’ message. This was annoying, because in theory anything that works on Dev should work on production. Grrrr. - I then followed step 23 on Dominics list and edited my Gemfile. The format of my text was slightly different though, and I replaced the line gem ‘sqlite3′ with
group :development, :test do
gem ‘sqlite3′
end
group :production do
gem ‘pg’
end - I then did another git commit and push heroku (steps 24 – 26), but still no joy.
- I discovered that two final tweaks were required to make the app happy. First I had to edit database.yml, found under appname/config. In there is a reference to the production database, so I replaced the production settings with:
production:
adapter: postgresql
database: db/production.postgresql
pool: 5
timeout: 5000
As heroku apparently prefers postgres to sqlite3. - Next I had to edit Gemfile.lock which is found in the root of the app folder, and remove the lines:
PLATFORMS
x86-mingw32
As Heroku apparently has something against apps generated on Windows! - A final repeat of steps 24-26, and it was happy days as my deployed app displayed ‘Say#hello Find me in app/views/say/hello.html.erb‘ when I browsed to http://furious-sunrise-9610.herokuapp.com/say/hello/
It appears that Heroku prefers RoR apps developed on a Mac or Linux platform. My step 12 wouldn’t have been needed had I produced the app on a non-windows setup (I think).
Now that I can actually deploy an app, I’m going to have a crack at developing something slightly more sophisticated than hello world. But first, I’ve decided that I should ensure that my development environment mimics the production environment as closely as possible, so its time to try and get postgres working on my local machine, and to get my local apps talking to it. Wish me luck.
How about running a Linux Virtual Machine to dev on… Maybe I can show you how sometime!
Hi Ben, yes I’d be interested to learn about that… Can I create one on my win7 box? I did mess around with ubuntu a while ago which seemed pretty neat.
We have tried Heroku, It’s really great Service provider.