Sha256: e2dc7b835eb5001c5d71a7fd561731ecdc5aaf8d8d97a531d6a4e20b984b0326

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

module Formol
  class Admin::CategoriesController < Admin::AdminController
    respond_to :html, :except => [:sort]
    respond_to :js,   :only   => [:sort]
    
    def index
      categories
    end
    
    def new
      category
    end
    
    def create
      if category.save
        respond_with(category, :status => :created, :location => admin_categories_path)
      else
        respond_with(category, :status => :unprocessable_entity) do |format|
          format.html { render :new }
        end
      end
    end
    
    def edit
      category
    end
    
    def update
      if category.update_attributes(params[:category])
        respond_with(category, :location => admin_categories_path)
      else
        respond_with(category) do |format|
          format.html { render :edit }
        end
      end
    end
    
    def destroy
      category.destroy
      
      respond_with(category, :location => admin_categories_path)
    end
    
    def sort
      Formol::Category.sort(params[:categories])
      
      render :nothing => true, :status => :ok
    end
    
    protected
    
    def categories
      @categories ||= Formol::Category.ready_for_listing.all
    end
    
    def category
      @category ||= (params[:id].present? ? Formol::Category.find(params[:id]) : Formol::Category.new(params[:category]))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formol-0.0.6 app/controllers/formol/admin/categories_controller.rb
formol-0.0.5 app/controllers/formol/admin/categories_controller.rb
formol-0.0.4 app/controllers/formol/admin/categories_controller.rb