Sha256: dcc2239d033d59df1bf6bd8c7d96ae51f57615d017d5977ded9ab3d12e46f855

Contents?: true

Size: 1.86 KB

Versions: 8

Compression:

Stored size: 1.86 KB

Contents

class Spud::Admin::SnippetsController < Spud::Admin::ApplicationController
  belongs_to_spud_app :snippets
  layout '/spud/admin/detail'
  add_breadcrumb "Snippets", :spud_admin_snippets_url

  before_filter :load_snippet, :only => [:show, :edit, :update, :destroy]

  # cache_sweeper :snippet_sweeper, :only => [:update,:destroy,:create]

  def index
    @snippets = SpudSnippet.site(session[:admin_site]).order(:name).paginate :page => params[:page]

    respond_with @snippets
  end

  def new
    add_breadcrumb "New", :new_spud_admin_snippet_url
    @snippet = SpudSnippet.new
    respond_with @snippet
  end

  def create
    add_breadcrumb "New", :new_spud_admin_snippet_url
    @snippet = SpudSnippet.new(snippet_params)
    @snippet.site_id = session[:admin_site]

    @snippet.save

    respond_with @snippet, :location => spud_admin_snippets_url
  end

  def edit
    add_breadcrumb "Edit", :edit_spud_admin_snippet_url

    respond_with @snippet
  end

  def update
    add_breadcrumb "Edit", :edit_spud_admin_snippet_url
    flash[:notice] = "Snippet saved successfully!" if @snippet.update_attributes(snippet_params)
    respond_with @snippet, :location => spud_admin_snippets_url
  end

  def destroy
    flash[:notice] = "Snippet removed!" if @snippet.destroy
    respond_with @snippet,:location => spud_admin_snippets_url
  end


private
  def load_snippet
    @snippet = SpudSnippet.where(:id => params[:id]).first
    if @snippet.blank?
      flash[:error] = "Snippet does not exist!"
      redirect_to spud_admin_snippets_url and return false
    elsif Spud::Core.multisite_mode_enabled && @snippet.site_id != session[:admin_site]
      flash[:warning] = "This snippet is for a different site"
      redirect_to spud_admin_snippets_url and return false
    end
  end

  def snippet_params
    params.require(:spud_snippet).permit(:content, :content_processed, :format, :name)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spud_cms-1.0.2 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.1 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.0 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.0.rc1.4 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.0.rc1.3 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.0.rc1.2 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.0.rc1.1 app/controllers/spud/admin/snippets_controller.rb
spud_cms-1.0.0.RC1 app/controllers/spud/admin/snippets_controller.rb