Sha256: 4ba7a122e823701fcbbc5088a2e5bfa9a1fdf062808500bb7c082a754337b3e1

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

class Spud::Admin::BannerSetsController < Spud::Admin::ApplicationController
  before_filter :get_record, :only => [:show, :edit, :update, :destroy]
  respond_to :html
  belongs_to_spud_app :banner_sets
  add_breadcrumb 'Banner Sets', :spud_admin_banner_sets_path
  layout false

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

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

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

  def create
    @banner_set = SpudBannerSet.new(banner_set_params)
    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(banner_set_params)
      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 spud_admin_banner_sets_path
      return false
    end
  end

  def banner_set_params
    params.require(:spud_banner_set).permit(:cropped, :height, :name, :short_name, :width)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spud_banners-1.0.0 app/controllers/spud/admin/banner_sets_controller.rb
spud_banners-1.0.0.rc1 app/controllers/spud/admin/banner_sets_controller.rb