Sha256: 6d9218bf58d7581284fbaca0816b8cc4911ef0542ec6cae597ca08f239e4a50c

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

class Admin::Carousel::SlidesController < Admin::Carousel::BaseController
  
  before_filter :load_carousel
  before_filter :build_slide, :only => [:new, :create]
  before_filter :load_slide,  :only => [:edit, :update, :destroy]
  
  def index
    @slides = @carousel.slides
  end

  def new
    render
  end

  def edit
    render
  end

  def create
    @slide.save!
    flash[:notice] = 'Slide created'
    redirect_to :action => :index
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create Slide'
    render :action => :new
  end

  def update
   @slide.update_attributes!(params[:slide])
    flash[:notice] = 'Slide updated'
    redirect_to :action => :edit
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update Slide'
    render :action => :edit
  end

  def destroy
    @slide.destroy
    flash[:notice] = 'Slide deleted'
    redirect_to :action => :index
  end
  
  def reorder
    (params[:carousel_slide] || []).each_with_index do |id, index|
      Carousel::Slide.where(:id => id).update_all(:position => index)
    end
    render :nothing => true
  end

protected

  def build_slide
    @slide = @carousel.slides.new(params[:slide])
  end

  def load_slide
    @slide = @carousel.slides.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Slide not found'
    redirect_to :action => :index
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfy_carousel-0.0.1 app/controllers/admin/carousel/slides_controller.rb