Sha256: 60be18197ef3a46a53dee3afce9427163c93c932cf20f15b12e392297b345c04

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

class SofaGallery::Admin::GalleriesController < SofaGallery::Admin::BaseController
  
  before_filter :load_gallery,  :except => [:index, :new, :create]
  before_filter :build_gallery, :only   => [:new, :create]
  
  def index
    @galleries = SofaGallery::Gallery.all
  end
  
  def new
    render
  end
  
  def create
    @gallery.save!
    flash[:notice] = 'Gallery created'
    redirect_to :action => :index
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create Gallery'
    render :action => :new
  end
  
  def show
    render
  end
  
  def edit
    render
  end
  
  def update
    @gallery.update_attributes!(params[:gallery])
    flash[:notice] = 'Gallery updated'
    redirect_to :action => :index
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update Gallery'
    render :action => :edit
  end
  
  def destroy
    @gallery.destroy
    flash[:notice] = 'Gallery deleted'
    redirect_to :action => :index
  end
  
protected
  
  def load_gallery
    @gallery = SofaGallery::Gallery.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Gallery not found'
    redirect_to :action => :index
  end
  
  def build_gallery
    @gallery = SofaGallery::Gallery.new(params[:gallery])
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sofa_gallery-0.0.2 app/controllers/sofa_gallery/admin/galleries_controller.rb
sofa_gallery-0.0.1 app/controllers/sofa_gallery/admin/galleries_controller.rb