PageRenderTime 1197ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

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

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