/api/app/controllers/spree/api/taxonomies_controller.rb
Ruby | 56 lines | 46 code | 9 blank | 1 comment | 2 complexity | c24c56c236b8bd7de5f9eaed6eacd6ad MD5 | raw file
Possible License(s): BSD-3-Clause
- 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
- # Because JSTree wants parameters in a *slightly* different format
- def jstree
- show
- 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