Allow for an override of the host so that the CmsSite can be forced

Ryan Garver committed Mar 17, 2011
commit 152dfdc90646af8f230467036a84decfee47d64c
Showing 4 changed files with 20 additions and 6 deletions
app/controllers/cms_admin/base_controller.rb +4 -3
@@ @@ -13,16 +13,17 @@ class CmsAdmin::BaseController < ActionController::Base
protected
def load_admin_cms_site
- @cms_site = CmsSite.find_by_hostname!(request.host.downcase)
+ hostname = ComfortableMexicanSofa.config.override_host || request.host.downcase
+ @cms_site = CmsSite.find_by_hostname!(hostname)
rescue ActiveRecord::RecordNotFound
if ComfortableMexicanSofa.config.auto_manage_sites
if CmsSite.count == 0
- @cms_site = CmsSite.create!(:label => 'Default Site', :hostname => request.host.downcase)
+ @cms_site = CmsSite.create!(:label => 'Default Site', :hostname => hostname)
elsif CmsSite.count == 1
@cms_site = CmsSite.first
- @cms_site.update_attribute(:hostname, request.host.downcase)
+ @cms_site.update_attribute(:hostname, hostname)
end
end
app/controllers/cms_content_controller.rb +1 -1
@@ @@ -22,7 +22,7 @@ class CmsContentController < ApplicationController
protected
def load_cms_site
- @cms_site = CmsSite.find_by_hostname!(request.host.downcase)
+ @cms_site = CmsSite.find_by_hostname!(ComfortableMexicanSofa.config.override_host || request.host.downcase)
rescue ActiveRecord::RecordNotFound
render :text => 'Site Not Found', :status => 404
end
config/initializers/comfortable_mexican_sofa.rb +6 -1
@@ @@ -31,7 +31,12 @@ ComfortableMexicanSofa.configure do |config|
# page caching for CMS Layout CSS and Javascript. Enabled by default. When deploying
# to an environment with read-only filesystem (like Heroku) turn this setting off.
# config.enable_caching = true
-
+
+ # Override the host used to look up the active CmsSite. If you are not
+ # planning on using the site features, I recommend you set this override to
+ # limit unexpected "Site not found" errors when you try to hit app01.example.com
+ # instead of www.example.com.
+ # config.override_host = "www.exmample.com"
end
# Default credentials for ComfortableMexicanSofa::HttpAuth
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb +9 -1
@@ @@ -26,6 +26,12 @@ class ComfortableMexicanSofa::Configuration
# Caching for css/js. For admin layout and ones for cms content. Enabled by default.
attr_accessor :enable_caching
+
+ # Upload settings
+ attr_accessor :upload_file_options
+
+ # Override the hostname when looking up which site to use
+ attr_accessor :override_host
# Configuration defaults
def initialize
@@ @@ -37,6 +43,8 @@ class ComfortableMexicanSofa::Configuration
@auto_manage_sites = true
@disable_irb = true
@enable_caching = true
+ @upload_file_options = {}
+ @override_host = nil
end
- end
\ No newline at end of file
+ end