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

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

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