Ruby on Rails with Google Gears
Thursday, May 31st, 2007Prelude
This post is just my head throwing ideas about. Non of which are fully formed, nor fully investigated.
Intro
Today Google labs spitted out an early “plugin” for Internet explorer and firefox to make websites viewable and interactive offline. This isn’t entirely new as Apollo offers something similar. However, this is interesting considering Google is one of the kings of webapps. With Gmail, Google Calender and Google Docs all obviously the target for this technology I doubt that it would fail spectacularly.
Very brief and rubbish Gears overview
First off, there are two main components to Gears. The webserver and the database. The webserver is pretty simple to get our heads round, it essentailly caches pages that us as developers tell it to. For me the most interesting parts is the database.
The Gears Plugin that the user installs includes a fully relational SQLite database. As developers we can interacted with it by passing SQL commands via javascript. Yes thats right… we interact with it by using javascript code such as
var rs = db.execute('select * from Demo order by Timestamp desc');
The benifits of this are pretty interesting. For example webservers technically don’t have to store information at their end, ever, just relying upon the users own store.
I feel however the most use of such an app would be for something like gmail, where when you are offline you write and send an email with gears facilitating the actual sending of the email when the internet becomes available.
So how would Rails fit into all of this?
I love writing webapps in rails. Its quick, easy and Ruby is lovely to write. So could developing a Rails app with gears functionality be a possibility without having to drop into insane javascripty-SQL-type goo every time?
The answer in my opinion is yes, but it won’t be easy.
Here are the major barriers in the way to making a my ideal acts_as_gears type plugin.
- The plugin should be able to convert Ruby into javascript for offline controllers and model interactions. A massive undertaking (possibly recreating active record in javascript.. shudder).
- Creating the user’s local database and linking each column with the live database columns would be essential if we wanted to do any sort of syncing.
- The automatic creation of database syncing methods in javascript and ruby.
- Creating a seamlessness of data origin in views. For example, a table of information should be able to be printed out on one page irrespective if data came via the live or local database.
- The views should only have to be writen once, with of cause different javascript payloads.
- Loading and unloading of data needs and state management.
Anyway that’s what’s on my mind right now, a half baked whirlpool of rails, javascript and gears.