Sha256: 9f2e3843d02a498f3a7c5d56cb70f32c8e8dbd2933b94a31214b393535756f30

Contents?: true

Size: 1.34 KB

Versions: 9

Compression:

Stored size: 1.34 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.all(:order => 'label')
  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
    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
    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

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

9 entries across 9 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.3.8 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.7 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.6 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.5 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.4 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.3 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.2 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.1 app/controllers/cms_admin/snippets_controller.rb
comfortable_mexican_sofa-1.3.0 app/controllers/cms_admin/snippets_controller.rb