Sha256: 6ab2fea7cd303981da64e167bf9937b80f5b6cf6c5036d93480ccfc12110361a

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

class Admin::BannerSetsController < Admin::ApplicationController

  cache_sweeper :spud_banner_sweeper, :only => [:create, :update, :destroy]
  before_filter :get_record, :only => [:show, :edit, :update, :destroy]
  respond_to :html
  belongs_to_spud_app :banner_sets
  add_breadcrumb 'Banner Sets', :admin_banner_sets_path
  layout false

  def index
    @banner_sets = SpudBannerSet.all
    respond_with @banner_sets, :layout => 'admin/detail'
  end

  def show
    respond_with @banner_set, :layout => 'admin/detail'
  end

  def new
    @banner_set = SpudBannerSet.new
    respond_with @banner_set
  end

  def create
    @banner_set = SpudBannerSet.new(params[:spud_banner_set])
    if @banner_set.save
      flash.now[:notice] = 'BannerSet created successfully' 
      render 'create'
    else
      render 'new', :status => 422
    end
  end

  def edit
    respond_with @banner_set
  end

  def update
    if @banner_set.update_attributes(params[:spud_banner_set])
      flash.now[:notice] = 'BannerSet updated successfully'
      @banner_set.reprocess_banners!
      render 'create'
    else
      render 'edit', :status => 422
    end
  end

  def destroy
    if @banner_set.destroy
      flash.now[:notice] = 'BannerSet deleted successfully' 
    end
    render :nothing => true
  end

private

  def get_record
    begin
      logger.debug "Looking for banner set with id: #{params[:id]}"
      @banner_set = SpudBannerSet.find(params[:id])
    rescue ActiveRecord::RecordNotFound => e
      flash.now[:error] = "Could not find the requested BannerSet"
      redirect_to admin_banner_sets_path
      return false
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tb_banners-1.0.2 app/controllers/admin/banner_sets_controller.rb