Sha256: 0202bee217fdd0edeb13cc03a2e413adee2787a6b490a49a313206f33b25cd6f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class CmsAdmin::BaseController < ApplicationController
  
  protect_from_forgery
  
  # Authentication module must have #authenticate method
  include ComfortableMexicanSofa.config.authentication.to_s.constantize
  
  before_filter :authenticate,
                :load_admin_cms_site,
                :load_fixtures
  
  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
  
  def load_fixtures
    return unless ComfortableMexicanSofa.config.enable_fixtures
    ComfortableMexicanSofa::Fixtures.sync(@cms_site)
    flash.now[:error] = 'CMS Fixtures are enabled. All changes done here will be discarded.'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.2.3 app/controllers/cms_admin/base_controller.rb