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

Instance Method Details

#createObject



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

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

#destroyObject



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

def destroy
  authorize! :destroy, zone
  zone.destroy
  respond_with(zone, status: 204)
end

#indexObject



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

def index
  @zones = Spree::Zone.
    accessible_by(current_ability, :read).
    order('name ASC').
    ransack(params[:q]).
    result

  @zones = paginate(@zones)

  respond_with(@zones)
end

#showObject



32
33
34
# File 'app/controllers/spree/api/zones_controller.rb', line 32

def show
  respond_with(zone)
end

#updateObject



36
37
38
39
40
41
42
43
# File 'app/controllers/spree/api/zones_controller.rb', line 36

def update
  authorize! :update, zone
  if zone.update_attributes(zone_params)
    respond_with(zone, status: 200, default_template: :show)
  else
    invalid_resource!(zone)
  end
end