Class: Spree::Api::ProductsController

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



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

def create
  authorize! :create, Product
  params[:product][:available_on] ||= Time.now
  @product = Product.new(params[:product])
  if @product.save
    respond_with(@product, :status => 201, :default_template => :show)
  else
    invalid_resource!(@product)
  end
end

#destroyObject



47
48
49
50
51
52
53
# File 'app/controllers/spree/api/products_controller.rb', line 47

def destroy
  authorize! :delete, Product
  @product = find_product(params[:id])
  @product.update_attribute(:deleted_at, Time.now)
  @product.variants_including_master.update_all(:deleted_at => Time.now)
  respond_with(@product, :status => 204)
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/spree/api/products_controller.rb', line 6

def index
  if params[:ids]
    @products = product_scope.where(:id => params[:ids])
  else
    @products = product_scope.ransack(params[:q]).result
  end

  @products = @products.page(params[:page]).per(params[:per_page])

  respond_with(@products)
end

#newObject



23
24
# File 'app/controllers/spree/api/products_controller.rb', line 23

def new
end

#showObject



18
19
20
21
# File 'app/controllers/spree/api/products_controller.rb', line 18

def show
  @product = find_product(params[:id])
  respond_with(@product)
end

#updateObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/spree/api/products_controller.rb', line 37

def update
  authorize! :update, Product
  @product = find_product(params[:id])
  if @product.update_attributes(params[:product])
    respond_with(@product, :status => 200, :default_template => :show)
  else
    invalid_resource!(@product)
  end
end