Skip to content

Instantly share code, notes, and snippets.

@hughevans
Forked from pat/application_controller.rb
Created July 13, 2009 06:54
Show Gist options
  • Save hughevans/145974 to your computer and use it in GitHub Desktop.
Save hughevans/145974 to your computer and use it in GitHub Desktop.
# Three things to add:
# * before_filter call
# * action_has_layout? method (if you have one, combine them)
# * adjust_for_inline
#
class ApplicationController < ActionController::Base
# ...
before_filter :adjust_for_inline
# ...
private
# We don't want no stinking layout if it's an AJAX request.
def action_has_layout?
request.format != :inline && super
end
# Careful not to bugger up JS/other XHR requests
def adjust_for_inline
request.format = :inline if request.format == :html && request.xhr?
end
# ...
end
# Add this line to your existing file.
# Jury's out on the best name for the pseudo-mimetype though.
Mime::Type.register_alias "text/html", :inline
# A long time ago, in an action far far away
def index
# ...
respond_to do |wants|
wants.inline {
render :template => 'controller/_partial'
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment