Monday, July 14, 2008

Take your Rails application offline with the Gears on Rails project



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).

9 comments:

  1. Hi, I'm the author of Jester. This is a totally awesome plugin, and a great usage of the Jester library. I'd like to use this in a Camping app, I might have to fork it or something to make it less Rails-specific.

    I'd love to send Michael and Rui an email or something, but I can't find their presence or contact info online. I'll risk posting my email up here publicly -- it's emill@thoughtbot.com, if they want to reach me about anything.

    Great work!

    ReplyDelete
  2. I'm thrilled that this is getting so much attention! Guess the pressure's on now. :)

    We've created a blog around the Gears on Rails project for ideas and updates, and we'll post as often as we can.

    http://gearsonrails.blogspot.com/

    ReplyDelete
  3. Database synchronization is a big problem with offline Web applications.

    What plans do you have?

    This project caught my eye:
    http://symmetricds.sourceforge.net/

    Combining it with Google Gears could be a good solution.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. @Tom

    It looks like the SymmetricDS project has not been implemented with SQLite yet, which I believe is what Gears uses.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. Since so many times there is no update for this project, any problem? or what?

    ReplyDelete