Class: Spree::Api::V1::OptionTypesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/option_types_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#content_type, #permitted_line_item_attributes

Methods included from ControllerSetup

included

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/spree/api/v1/option_types_controller.rb', line 27

def create
  authorize! :create, Spree::OptionType
  @option_type = Spree::OptionType.new(option_type_params)
  if @option_type.save
    render :show, status: 201
  else
    invalid_resource!(@option_type)
  end
end

#destroyObject



46
47
48
49
50
# File 'app/controllers/spree/api/v1/option_types_controller.rb', line 46

def destroy
  @option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])
  @option_type.destroy
  render plain: nil, status: 204
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/spree/api/v1/option_types_controller.rb', line 5

def index
  @option_types =  if params[:ids]
                     Spree::OptionType.
                       includes(:option_values).
                       accessible_by(current_ability, :read).
                       where(id: params[:ids].split(','))
                   else
                     Spree::OptionType.
                       includes(:option_values).
                       accessible_by(current_ability, :read).
                       load.ransack(params[:q]).result
                   end
  respond_with(@option_types)
end

#newObject



25
# File 'app/controllers/spree/api/v1/option_types_controller.rb', line 25

def new; end

#showObject



20
21
22
23
# File 'app/controllers/spree/api/v1/option_types_controller.rb', line 20

def show
  @option_type = Spree::OptionType.accessible_by(current_ability, :read).find(params[:id])
  respond_with(@option_type)
end

#updateObject



37
38
39
40
41
42
43
44
# File 'app/controllers/spree/api/v1/option_types_controller.rb', line 37

def update
  @option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])
  if @option_type.update_attributes(option_type_params)
    render :show
  else
    invalid_resource!(@option_type)
  end
end