Sha256: acb3878a15684932f122686f0d099a624c3b309d93fa43fb7cd8a3eb20b62ae0

Contents?: true

Size: 1.62 KB

Versions: 23

Compression:

Stored size: 1.62 KB

Contents

class CmsAdmin::SnippetsController < CmsAdmin::BaseController

  before_filter :build_snippet, :only => [:new, :create]
  before_filter :load_snippet,  :only => [:edit, :update, :destroy]

  def index
    return redirect_to :action => :new if @site.snippets.count == 0
    @snippets = @site.snippets.includes(:categories).for_category(params[:category])
  end

  def new
    render
  end

  def edit
    render
  end

  def create
    @snippet.save!
    flash[:notice] = I18n.t('cms.snippets.created')
    redirect_to :action => :edit, :id => @snippet
  rescue ActiveRecord::RecordInvalid
    logger.detailed_error($!)
    flash.now[:error] = I18n.t('cms.snippets.creation_failure')
    render :action => :new
  end

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

  def destroy
    @snippet.destroy
    flash[:notice] = I18n.t('cms.snippets.deleted')
    redirect_to :action => :index
  end
  
  def reorder
    (params[:cms_snippet] || []).each_with_index do |id, index|
      Cms::Snippet.where(:id => id).update_all(:position => index)
    end
    render :nothing => true
  end

protected

  def build_snippet
    @snippet = @site.snippets.new(params[:snippet])
  end

  def load_snippet
    @snippet = @site.snippets.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = I18n.t('cms.snippets.not_found')
    redirect_to :action => :index
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.6.8 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.6.7 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.6.6 app/controllers/cms_admin/snippets_controller.rb