Sha256: 8c52338d89f557e19e76183687eabce6d6e8893659b01ba792c7988787c8ef41

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class CmsAdmin::SnippetsController < CmsAdmin::BaseController

  before_filter :build_cms_snippet, :only => [:new, :create]
  before_filter :load_cms_snippet,  :only => [:edit, :update, :destroy]

  def index
    return redirect_to :action => :new if @cms_site.snippets.count == 0
    @cms_snippets = @cms_site.snippets.all(:order => 'label')
  end

  def new
    render
  end

  def edit
    render
  end

  def create
    @cms_snippet.save!
    flash[:notice] = 'Snippet created'
    redirect_to (params[:commit] ? {:action => :index} : {:action => :edit, :id => @cms_snippet})
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create snippet'
    render :action => :new
  end

  def update
    @cms_snippet.update_attributes!(params[:cms_snippet])
    flash[:notice] = 'Snippet updated'
    redirect_to (params[:commit] ? {:action => :index} : {:action => :edit, :id => @cms_snippet})
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update snippet'
    render :action => :edit
  end

  def destroy
    @cms_snippet.destroy
    flash[:notice] = 'Snippet deleted'
    redirect_to :action => :index
  end

protected

  def build_cms_snippet
    @cms_snippet = @cms_site.snippets.new(params[:cms_snippet])
  end

  def load_cms_snippet
    @cms_snippet = @cms_site.snippets.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Snippet not found'
    redirect_to :action => :index
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.1.2 app/controllers/cms_admin/snippets_controller.rb