Sha256: be77514de9e15fbe8e445ec4200cb1957de24d5b8fe391c773565bfbc4301fef

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

module Spree
  module Api
    class TaxonomiesController < Spree::Api::BaseController
      respond_to :json

      def index
        @taxonomies = Taxonomy.order('name').includes(:root => :children).ransack(params[:q]).result
          .page(params[:page]).per(params[:per_page])
        respond_with(@taxonomies)
      end

      def show
        @taxonomy = Taxonomy.find(params[:id])
        respond_with(@taxonomy)
      end

      def create
        authorize! :create, Taxonomy
        @taxonomy = Taxonomy.new(params[:taxonomy])
        if @taxonomy.save
          respond_with(@taxonomy, :status => 201, :default_template => :show)
        else
          invalid_resource!(@taxonomy)
        end
      end

      def update
        authorize! :update, Taxonomy
        if taxonomy.update_attributes(params[:taxonomy])
          respond_with(taxonomy, :status => 200, :default_template => :show)
        else
          invalid_resource!(taxonomy)
        end
      end

      def destroy
        authorize! :delete, Taxonomy
        taxonomy.destroy
        respond_with(taxonomy, :status => 204)
      end

      private

      def taxonomy
        @taxonomy ||= Taxonomy.find(params[:id])
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
spree_api-1.3.1 app/controllers/spree/api/taxonomies_controller.rb
spree_api-1.3.0 app/controllers/spree/api/taxonomies_controller.rb
spree_api-1.3.0.rc2 app/controllers/spree/api/taxonomies_controller.rb
dup_spree_api-1.3.0.rc1 app/controllers/spree/api/taxonomies_controller.rb