Class: Spree::Api::StockLocationsController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/spree/api/stock_locations_controller.rb', line 13

def create
  authorize! :create, StockLocation
  @stock_location = StockLocation.new(params[:stock_location])
  if @stock_location.save
    respond_with(@stock_location, status: 201, default_template: :show)
  else
    invalid_resource!(@stock_location)
  end
end

#destroyObject



32
33
34
35
36
# File 'app/controllers/spree/api/stock_locations_controller.rb', line 32

def destroy
  authorize! :delete, StockLocation
  stock_location.destroy
  respond_with(stock_location, :status => 204)
end

#indexObject



4
5
6
7
# File 'app/controllers/spree/api/stock_locations_controller.rb', line 4

def index
  @stock_locations = StockLocation.order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  respond_with(@stock_locations)
end

#showObject



9
10
11
# File 'app/controllers/spree/api/stock_locations_controller.rb', line 9

def show
  respond_with(stock_location)
end

#updateObject



23
24
25
26
27
28
29
30
# File 'app/controllers/spree/api/stock_locations_controller.rb', line 23

def update
  authorize! :update, StockLocation
  if stock_location.update_attributes(params[:stock_location])
    respond_with(stock_location, status: 200, default_template: :show)
  else
    invalid_resource!(stock_location)
  end
end