Created
March 18, 2009 19:19
-
-
Save nbibler/81330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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