Take your Rails application offline with the Gears on Rails project

July 14, 2008


Link copied to clipboard


Michael Marcus and Rui Ma, two recent graduates from a masters program at NYU, join us to discuss Gears on Rails, their open source framework that makes it easier than ever to take a Rails code-base offline.

We start out discussing the genesis of the project and what it is trying to do. The sweet spot is building a Rails application that can handle local interactions without having to drop down to Gears JavaScript APIs themselves.

First you install the Gears on Rails plugin via:
ruby script /plugin install http://gearsonrails.googlecode.com/svn/trunk/acts_as_local
Then you can create a Rails controller and tell it that it is local via acts_as_local :except=>['hello'].

Now you can create an action in the controller by creating a method that uses an API that looks Rails-like:
def create_local
'
post = Post.build(params("post"));
Post.create_local(post);
window.location.reload( false );
'
end
In that string, the framework is actually building on Jester, a "JavaScript client for REST APIs that uses Rails conventions". Rui explained how they built out the local versions of the calls.

This means that your architecture revolves around REST calls, and when you are offline they all occur on local data that can sync up later. The synchronization is done for you automatically.

Thanks to Michael and Rui for taking the time to discuss their project with us, and thank you for reading.

Listen to the audio interview directly (or subscribe via iTunes).