Sha256: b44a7d9b1473c49becc47d28dd61221f72348adc0db317176ccd3d78da10cf65

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

class CmsAdmin::LayoutsController < CmsAdmin::BaseController
  
  before_filter :build_cms_layout,  :only => [:new, :create]
  before_filter :load_cms_layout,   :only => [:edit, :update, :destroy]
  
  def index
    return redirect_to :action => :new if @cms_site.cms_layouts.count == 0
    @cms_layouts = @cms_site.cms_layouts.roots
  end
  
  def new
    render
  end
  
  def edit
    render
  end
  
  def create
    @cms_layout.save!
    flash[:notice] = 'Layout created'
    redirect_to :action => :edit, :id => @cms_layout
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create layout'
    render :action => :new
  end
  
  def update
    @cms_layout.update_attributes!(params[:cms_layout])
    flash[:notice] = 'Layout updated'
    redirect_to :action => :edit, :id => @cms_layout
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update layout'
    render :action => :edit
  end
  
  def destroy
    @cms_layout.destroy
    flash[:notice] = 'Layout deleted'
    redirect_to :action => :index
  end
  
protected
  
  def build_cms_layout
    @cms_layout = @cms_site.cms_layouts.new(params[:cms_layout])
    @cms_layout.parent ||= CmsLayout.find_by_id(params[:parent_id])
    @cms_layout.content ||= '{{ cms:page:content:text }}'
  end
  
  def load_cms_layout
    @cms_layout = @cms_site.cms_layouts.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Layout not found'
    redirect_to :action => :index
  end
  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.0.51 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.50 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.49 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.48 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.47 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.46 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.45 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.44 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.43 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.42 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.0.41 app/controllers/cms_admin/layouts_controller.rb