layout false if request.xhr?
Rather simple actually… since ActionController::Base.layout takes a proc, and calls it upon a request.
class ApplicationController < ActionController::Base
def self.without_layout_on_xhr
layout proc { |controller| controller.in_popup? ? nil : "application" }
end
def in_popup?
request.xhr?
end
end
class BusyWorkController < ApplicationController
without_layout_on_xhr
before_filter :login_required
def new
@work = Busy.new
end
endI’ve abstracted out the conditions for rendering without a template based on the controller instance method #in_popup?. Feel free to change it to whatever you want.
