Sha256: 8c783625f382ebe24d6267d4a3b2850020e94f5ebafc7fec06bf3fd004178ae3

Contents?: true

Size: 951 Bytes

Versions: 2

Compression:

Stored size: 951 Bytes

Contents

class CmsAdmin::BaseController < ActionController::Base
  
  protect_from_forgery
  
  # Authentication module must have #authenticate method
  include ComfortableMexicanSofa.config.authentication.to_s.constantize
  
  before_filter :authenticate,
                :load_admin_cms_site
  
  layout 'cms_admin'
  
protected
  
  def load_admin_cms_site
    hostname = request.host.downcase
    @cms_site = Cms::Site.find_by_hostname!(hostname)
    
  rescue ActiveRecord::RecordNotFound
    unless ComfortableMexicanSofa.config.enable_multiple_sites
      if Cms::Site.count == 0
        @cms_site = Cms::Site.create!(:label => 'Default Site', :hostname => hostname)
      else
        @cms_site = Cms::Site.first
        @cms_site.update_attribute(:hostname, hostname)
      end
    end
    
    unless @cms_site
      flash[:error] = 'No Site defined for this hostname. Create it now.'
      return redirect_to(cms_admin_sites_path)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.1.2 app/controllers/cms_admin/base_controller.rb
comfortable_mexican_sofa-1.1.1 app/controllers/cms_admin/base_controller.rb