/api/app/controllers/spree/api/taxonomies_controller.rb
https://github.com/joshnuss/spree-1 · Ruby · 58 lines · 48 code · 9 blank · 1 comment · 3 complexity · 99274b80a92665584e4fd7c2f36a0c7a MD5 · raw file
- 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])
- last_taxonomy = Spree::Taxonomy.order("updated_at ASC").last
- if stale?(:etag => last_taxonomy, :last_modified => last_taxonomy.updated_at)
- respond_with(@taxonomies)
- end
- 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(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! :destroy, taxonomy
- taxonomy.destroy
- respond_with(taxonomy, :status => 204)
- end
- private
- def taxonomy
- @taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
- end
- end
- end
- end