Skip to content

Instantly share code, notes, and snippets.

@nbibler
Created March 18, 2009 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbibler/81330 to your computer and use it in GitHub Desktop.
Save nbibler/81330 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
alias_method_chain :cache_page, :subdomain
private
##
# Inserts the currently requested subdomain as a directory in front of the
# cached file location. Assuming you've moved the default page cache
# storage location to /public/cache, a request to app1.example.com would be
# cached as:
#
# RAILS_ROOT/public/cache/app1/index.html
# (page_cache_directory/subdomain/request_path)
#
# If the request does not have a subdomain (a request directly to
# http://example.com), the subdomain cache directory will default to 'www'.
#
def cache_page_with_subdomain(content = nil, options = nil)
subdomain = request.subdomains.last
path = "/#{subdomain || 'www'}/"
path << case options
when Hash
url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))
when String
options
else
request.path
end
cache_page_without_subdomain(content, path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment