-
Get a monthly update on best practices for delivering successful software.
My most recent Pathfinder project calls for a pretty typical Ruby on Rails web application with two interesting additional components: a Facebook application and an iGoogle gadget. Though a Rails Facebook plugin was easy to find, Rails development tools for iGoogle weren't as thick on the ground.
First, a bit of background: iGoogle, Google's personalized-homepage service, offers developers two methods of application development:
Because of cross-domain security issues, gadgets that require authentication must be built using the iframe sandbox method. As it turns out, this method's a lot easier. Instead of building a whole new interface, you can just tart up your existing app with an iGoogle-optimized user interface. Why replicate your existing view logic with a bunch of iGoogle-specific JavaScript when you can just reskin and call it a day?
As it turns out, though, reskinning a Rails app for iGoogle isn't as simple as it might seem at first glance. I can think of three options. All have drawbacks:
session[:igoogle] => true) so that all subsequent requests get the iGoogle layout. The only problem is that visits to your normal application in the same browser will get polluted by the iGoogle flag. The iGoogle interface that works so well in a tiny iframe renders your main application almost unusable in a full browser window.None of these solutions is ideal, so let's hear from you, readers. How do you build Rails apps that lend themselves to efficient re-use within iGoogle or other sandboxed "gadget" contexts? Let us know in the comments.
Related posts:
Topics: iGoogle, Ruby on Rails
If I were doing this I would go with #2 and use a custom igoogle format in my url. I know this got backported to rails from merb, but I’m not sure on the details. In Merb, I would add a custom format to my controllers (provides xml, json, igoogle), create a custom layout (application.igoogle.erb), and ensure that all my url’s were generated and not hard coded strings (hard coding your url scheme is brittle). There may even be some templates that would benefit from being customized for small layouts (foo/index.igoogle.erb)
Does anyone know how this currently works in Rails? I’m dreading the transition back for Rails 3.
Comment by Antares Trader, Monday, January 12, 2009 @ 4:52 pm
I’d look into a combination approach of a JavaScript link rewriter and session-based handling. I’m thinking along the lines of checking to see if your app is iframed (anti-clickjacking method) and then rewrite/set session vars accordingly.
A combination approach with CSRF-type protection (hidden secret in window.name) will give you more control if you actually need to use iframes in your application.
Comment by Nathan Hammond, Monday, January 12, 2009 @ 8:59 pm
I’d define a custom MIME type in the Rails initializers:
Mime::Type.register_alias “text/html”, :igoogle
then in your respond_to block have a format.igoogle that renders the appropriate layout.
Store an igoogle flag in the session.
See http://www.locomotivation.com/blog/2008/06/29/redesign-your-site-in-place-using-rails-custom-mime-types.html for a similar setup.
Comment by Mark Thomas, Wednesday, January 14, 2009 @ 9:10 pm