Class: Spree::Api::ZonesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/zones_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



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

def create
  authorize! :create, Zone
  @zone = Zone.new(map_nested_attributes_keys(Spree::Zone, params[:zone]))
  if @zone.save
    respond_with(@zone, :status => 201, :default_template => :show)
  else
    invalid_resource!(@zone)
  end
end

#destroyObject



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

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

#indexObject



5
6
7
8
# File 'app/controllers/spree/api/zones_controller.rb', line 5

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

#showObject



10
11
12
# File 'app/controllers/spree/api/zones_controller.rb', line 10

def show
  respond_with(zone)
end

#updateObject



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

def update
  authorize! :update, Zone
  if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, params[:zone]))
    respond_with(zone, :status => 200, :default_template => :show)
  else
    invalid_resource!(zone)
  end
end