Turn off Rails' Layouts for AJAX Requests
December 20th, 2006
Here’s a quick snippet for your ApplicationController:
layout proc{ |c| c.request.xhr? ? false : "application" }
HTTP requests using get and post will be processed normally, but AJAX requests will be rendered with no layout. This saves you from having to put render :layout => false
every time you do an AJAX request.