Class: Spree::Api::OptionValuesController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/spree/api/option_values_controller.rb', line 18

def create
  authorize! :create, Spree::OptionValue
  @option_value = scope.new(option_value_params)
  if @option_value.save
    render :show, :status => 201
  else
    invalid_resource!(@option_value)
  end
end

#destroyObject



37
38
39
40
41
# File 'app/controllers/spree/api/option_values_controller.rb', line 37

def destroy
  @option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
  @option_value.destroy
  render :text => nil, :status => 204
end

#indexObject



4
5
6
7
8
9
10
11
# File 'app/controllers/spree/api/option_values_controller.rb', line 4

def index
  if params[:ids]
    @option_values = scope.where(:id => params[:ids])
  else
    @option_values = scope.ransack(params[:q]).result.distinct
  end
  respond_with(@option_values)
end

#showObject



13
14
15
16
# File 'app/controllers/spree/api/option_values_controller.rb', line 13

def show
  @option_value = scope.find(params[:id])
  respond_with(@option_value)
end

#updateObject



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

def update
  @option_value = scope.accessible_by(current_ability, :update).find(params[:id])
  if @option_value.update_attributes(option_value_params)
    render :show
  else
    invalid_resource!(@option_value)
  end
end