PageRenderTime 1131ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/api/app/controllers/spree/api/taxonomies_controller.rb

https://github.com/pageman/spree
Ruby | 56 lines | 46 code | 9 blank | 1 comment | 2 complexity | c24c56c236b8bd7de5f9eaed6eacd6ad MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Api
  3. class TaxonomiesController < Spree::Api::BaseController
  4. respond_to :json
  5. def index
  6. @taxonomies = Taxonomy.order('name').includes(:root => :children).
  7. ransack(params[:q]).result.
  8. page(params[:page]).per(params[:per_page])
  9. respond_with(@taxonomies)
  10. end
  11. def show
  12. @taxonomy = Taxonomy.find(params[:id])
  13. respond_with(@taxonomy)
  14. end
  15. # Because JSTree wants parameters in a *slightly* different format
  16. def jstree
  17. show
  18. end
  19. def create
  20. authorize! :create, Taxonomy
  21. @taxonomy = Taxonomy.new(params[:taxonomy])
  22. if @taxonomy.save
  23. respond_with(@taxonomy, :status => 201, :default_template => :show)
  24. else
  25. invalid_resource!(@taxonomy)
  26. end
  27. end
  28. def update
  29. authorize! :update, Taxonomy
  30. if taxonomy.update_attributes(params[:taxonomy])
  31. respond_with(taxonomy, :status => 200, :default_template => :show)
  32. else
  33. invalid_resource!(taxonomy)
  34. end
  35. end
  36. def destroy
  37. authorize! :delete, Taxonomy
  38. taxonomy.destroy
  39. respond_with(taxonomy, :status => 204)
  40. end
  41. private
  42. def taxonomy
  43. @taxonomy ||= Taxonomy.find(params[:id])
  44. end
  45. end
  46. end
  47. end