Class: Kms::Catalog::OptionTypesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Kms::Catalog::OptionTypesController
- Defined in:
- app/controllers/kms/catalog/option_types_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 |
# File 'app/controllers/kms/catalog/option_types_controller.rb', line 15 def create @option_type = OptionType.find_or_create_by(option_types_params) @product = Product.find_by_id(params[:product_id]) @product.option_types << @option_type unless @product.option_types.include?(@option_type) render json: @option_type end |
#destroy ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/controllers/kms/catalog/option_types_controller.rb', line 22 def destroy @product = Product.find_by_id(params[:product_id]) @option_type = @product.option_types.find(params[:id]) @product.option_types.delete @option_type @option_type.destroy if @option_type.products.empty? render json: @option_types end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/kms/catalog/option_types_controller.rb', line 5 def index if params[:product_id] @product = Product.find_by_id(params[:product_id]) @option_types = @product.option_types else @option_types = OptionType.all.uniq end render json: @option_types.to_json end |
#tags ⇒ Object
30 31 32 33 |
# File 'app/controllers/kms/catalog/option_types_controller.rb', line 30 def @product = Product.find_by_id(params[:product_id]) render json: @product.option_types.pluck(:tag).uniq.to_json end |