Class: Spree::Api::ProductsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys, #set_jsonp_format
included
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#index ⇒ Object
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
|
#new ⇒ Object
23
24
|
# File 'app/controllers/spree/api/products_controller.rb', line 23
def new
end
|
#show ⇒ Object
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
|
#update ⇒ Object
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
|