Sha256: a1136f9a0ca0d30463ca2527c2500ff712779db656266e3634667fec16a71869

Contents?: true

Size: 1.63 KB

Versions: 28

Compression:

Stored size: 1.63 KB

Contents

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

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

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

      # Because JSTree wants parameters in a *slightly* different format
      def jstree
        show
      end

      def create
        authorize! :create, Taxonomy
        @taxonomy = Taxonomy.new(taxonomy_params)
        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(taxonomy_params)
          respond_with(taxonomy, :status => 200, :default_template => :show)
        else
          invalid_resource!(taxonomy)
        end
      end

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

      private

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

      def taxonomy_params
        if params[:taxonomy] && !params[:taxonomy].empty?
          params.require(:taxonomy).permit(permitted_taxonomy_attributes)
        else
          {}
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
spree_api-2.2.14 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.13 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.12 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.11 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.10 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.9 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.12 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.8 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.11 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.7 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.10 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.9 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.6 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.5 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.8 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.4 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.3 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.2.2 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.7 app/controllers/spree/api/taxonomies_controller.rb
spree_api-2.1.6 app/controllers/spree/api/taxonomies_controller.rb