Sha256: 449ef4b347cf587221b12b7a9bec7c0efca36730ab85e9fa1e0a812834fb077e

Contents?: true

Size: 1005 Bytes

Versions: 4

Compression:

Stored size: 1005 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 = 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 => hostname)
      elsif CmsSite.count == 1
        @cms_site = CmsSite.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

4 entries across 4 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.0.51 app/controllers/cms_admin/base_controller.rb
comfortable_mexican_sofa-1.0.50 app/controllers/cms_admin/base_controller.rb
comfortable_mexican_sofa-1.0.49 app/controllers/cms_admin/base_controller.rb
comfortable_mexican_sofa-1.0.48 app/controllers/cms_admin/base_controller.rb