Class: Spree::Api::StoresController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



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

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

#destroyObject



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

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

#indexObject



6
7
8
9
10
# File 'app/controllers/spree/api/stores_controller.rb', line 6

def index
  authorize! :read, Store
  @stores = Store.accessible_by(current_ability, :read).all
  respond_with(@stores)
end

#showObject



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

def show
  authorize! :read, @store
  respond_with(@store)
end

#updateObject



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

def update
  authorize! :update, @store
  if @store.update_attributes(store_params)
    respond_with(@store, status: 200, default_template: :show)
  else
    invalid_resource!(@store)
  end
end