PageRenderTime 1585ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/api/app/controllers/spree/api/v1/option_types_controller.rb

http://github.com/spree/spree
Ruby | 60 lines | 53 code | 7 blank | 0 comment | 3 complexity | 72173677bf46805303d9adb2f8504174 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Api
  3. module V1
  4. class OptionTypesController < Spree::Api::BaseController
  5. def index
  6. @option_types = if params[:ids]
  7. Spree::OptionType.
  8. includes(:option_values).
  9. accessible_by(current_ability).
  10. where(id: params[:ids].split(','))
  11. else
  12. Spree::OptionType.
  13. includes(:option_values).
  14. accessible_by(current_ability).
  15. load.ransack(params[:q]).result
  16. end
  17. respond_with(@option_types)
  18. end
  19. def show
  20. @option_type = Spree::OptionType.accessible_by(current_ability, :show).find(params[:id])
  21. respond_with(@option_type)
  22. end
  23. def new; end
  24. def create
  25. authorize! :create, Spree::OptionType
  26. @option_type = Spree::OptionType.new(option_type_params)
  27. if @option_type.save
  28. render :show, status: 201
  29. else
  30. invalid_resource!(@option_type)
  31. end
  32. end
  33. def update
  34. @option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
  35. if @option_type.update(option_type_params)
  36. render :show
  37. else
  38. invalid_resource!(@option_type)
  39. end
  40. end
  41. def destroy
  42. @option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
  43. @option_type.destroy
  44. render plain: nil, status: 204
  45. end
  46. private
  47. def option_type_params
  48. params.require(:option_type).permit(permitted_option_type_attributes)
  49. end
  50. end
  51. end
  52. end
  53. end