*   \   &   ©   |   /   * *   \   &   ©   |   /   * *   \   &   ©   |   /   * *   \   &   ©   |   /   * *   \   &   ©   |   /   *

posts tagged 'rails'

Always render Rails views without the full layout when using AJAX & degradable javascript

Rails-fu

Been neck-deep in Ruby on Rails the last few months, here’s my first nugget o’ code wisdom:

With unobtrusive javascript all of my Rails views may or may not be getting called via AJAX. Adding “:layout => :false if request.xhr?” all the time was bad code smell.

Here’s a 4 liner to extend the ‘render’ method and check if the view, partial, EJS etc. are being called via an XmlHttpRequest, in which case we want to ignore the layout unless explicitly asked to. Throw it in your ApplicationController and degrade away!


def render(*args)
  	args.first[:layout] = false if request.xhr? and args.first[:layout].nil?
	super
end

Might package this little guy into a plugin I find it so handy

Slingshot gives a peek at the Joyent Connector source

Joyent leaps into the Rails blogosphere spotlight with Slingshot, a simple way to run Rails apps as desktop applications. I could have certainly used it with the blainedavis.com installation, which ran the site on big ol’ touchscreens. To keep it snappy we ran the site locally using Instant Rails. It wasn’t difficult to setup, but certainly wasn’t compile-&-forget. Like many other commenters I am concerned about Slingshot protecting the app’s source, performance issues, and how it will compete with Adobe’s Apollo, but this is a wonderful, wonderful idea.

More importantly David Young gives a brief peek at the Joyent Connector source code while showing it off, the tease: