A back-end for Backbone.js apps using Ruby, Sinatra and MongoDB

1 minute read

After recently writing about web app development using backbone and vagrant I’ve started to spend time immersing myself in Ruby and Ruby Gems. Tonight while catching up on articles in my Pocket I ran across the following Addy Osmani article on creating a back-end for Backbone.js apps:

Building Backbone.js Apps With Ruby, Sinatra, MongoDB and Haml

Sweet. In addition to Addy’s very awesome and open-source book Backbone Fundamentals, he’s also writing some useful related articles. And though I’d likely ditch haml in favor of emblem with swag, Addy’s article ought to be a good starting point for the Ruby newbie.

Building on my “you can do this on Windows too” mantra as of late, I also want to point out that, to get the linked tutorial to work correctly on Ubuntu running in a virtual machine on Windows using Vagrant, you need to configure Sinatra to bind to the server on ip (not just so that Vagrant will be able to port-forward from Windows to WEBrick onto the Ubuntu guest machine, like:

require 'sinatra'

# Listen on all interfaces in the development environment
set :bind, ''

get '/' do
   "Hello World! Is it " + settings.bind + " you're looking for?"

Here’s a screen-shot of the port-forwarded response from WEBrick for Sinatra in Chrome for Windows, a back-end for Backbone apps using Ruby:

Vagrant-forwarded response from WEBrick running in Ubuntu virtual machine on Windows

Leave a Comment