Sha256: d4f7feca6a1e96a6b6a442c27f65a415c82528d39c861589458d1e5acdcbbb76

Contents?: true

Size: 1.76 KB

Versions: 19

Compression:

Stored size: 1.76 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(params[:spud_snippet])
    @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(params[:spud_snippet])
    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
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
spud_cms-0.9.21 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.20 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.18 app/controllers/spud/admin/snippets_controller.rb
tb_cms-1.0 app/controllers/spud/admin/snippets_controller.rb
tb_cms-0.9.18 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.17 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.15 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.14 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.13 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.12 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.11 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.10 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.9 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.8 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.7 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.6 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.5 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.4 app/controllers/spud/admin/snippets_controller.rb
spud_cms-0.9.3 app/controllers/spud/admin/snippets_controller.rb