Most of the time I don\'t want to render a layout when the request comes from AJAX. To this end I\'ve been writing render :layout => !request.xhr? frequently
A normal after_filter won't work because we want to modify rendering.
How about hijacking render?
class ApplicationController < ActionController::Base
private
def render(options = nil, extra_options = {}, &block)
options = {:layout => !request.xhr?}.merge(options) unless options.nil?
super(options, extra_options)
end
end
Set the layout when calling render to override it. A bit ugly but should work.