Sha256: 0a7c28bb7a8d5aa58fadf2ee7fd10293bb959c2f6e14bc7b8a9a4f9351eff436

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

class CmsAdmin::SitesController < CmsAdmin::BaseController

  skip_before_action  :load_admin_site,
                      :load_fixtures

  before_action :build_site,  :only => [:new, :create]
  before_action :load_site,   :only => [:edit, :update, :destroy]

  def index
    return redirect_to :action => :new if Cms::Site.count == 0
    @site = Cms::Site.find_by_id(session[:site_id])
    @sites ||= Cms::Site.all
  end

  def new
    render
  end

  def edit
    render
  end

  def create
    @site.save!
    flash[:success] = I18n.t('cms.sites.created')
    redirect_to cms_admin_site_layouts_path(@site)
  rescue ActiveRecord::RecordInvalid
    logger.detailed_error($!)
    flash.now[:error] = I18n.t('cms.sites.creation_failure')
    render :action => :new
  end

  def update
    @site.update_attributes!(site_params)
    flash[:success] = I18n.t('cms.sites.updated')
    redirect_to :action => :edit, :id => @site
  rescue ActiveRecord::RecordInvalid
    logger.detailed_error($!)
    flash.now[:error] = I18n.t('cms.sites.update_failure')
    render :action => :edit
  end

  def destroy
    @site.destroy
    flash[:success] = I18n.t('cms.sites.deleted')
    redirect_to :action => :index
  end

protected

  def build_site
    @site = Cms::Site.new(site_params)
    @site.hostname ||= request.host.downcase
  end

  def load_site
    @site = Cms::Site.find(params[:id])
    I18n.locale = ComfortableMexicanSofa.config.admin_locale || @site.locale
  rescue ActiveRecord::RecordNotFound
    flash[:error] = I18n.t('cms.sites.not_found')
    redirect_to :action => :index
  end
  
  def site_params
    params.fetch(:site, {}).permit!
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.9.3 app/controllers/cms_admin/sites_controller.rb
comfortable_mexican_sofa-1.9.2 app/controllers/cms_admin/sites_controller.rb
comfortable_mexican_sofa-1.9.1 app/controllers/cms_admin/sites_controller.rb
comfortable_mexican_sofa-1.9.0 app/controllers/cms_admin/sites_controller.rb