Sha256: 466af326be08d45325d2a86173618a46ab4e279bec3a599cf9e7833c163e825b

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

class CmsAdmin::AttachmentsController < CmsAdmin::BaseController
  
  before_filter :load_attachment, :only => [:edit, :update, :destroy]
  
  def index
    @category_id = params[:filter][:category_id] rescue nil
    unless @category_id.blank?
      @cms_attachments = CmsAttachment.in_category(@category_id).paginate(:page => params[:page])
    else
      @cms_attachments = CmsAttachment.paginate(:page => params[:page])
    end
  end
  
  def new
    @cms_attachment = CmsAttachment.new
  end
  
  def edit
  end
  
  def create
    @cms_attachment = CmsAttachment.new(params[:cms_attachment])
    @cms_attachment.save!
    
    flash[:notice] = 'Attachment created'
    redirect_to :action => :edit, :id => @cms_attachment
  
  rescue ActiveRecord::RecordInvalid
    render :action => :new
  end
  
  def update
    @cms_attachment.update_attributes!(params[:cms_attachment])
    
    flash[:notice] = 'Attachment updated'
    redirect_to :action => :edit, :id => @cms_attachment
  
  rescue ActiveRecord::RecordInvalid
    render :action => :edit
  end
  
  def destroy
    @cms_attachment.destroy
    
    flash[:notice] = 'Attachment removed'
    redirect_to :action => :index
  end
  
protected

  def load_attachment
    @cms_attachment = CmsAttachment.find_by_id(params[:id])
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-0.0.18 app/controllers/cms_admin/attachments_controller.rb