89 lines
2.7 KiB
Ruby
89 lines
2.7 KiB
Ruby
module Suppliers
|
|
class ProductsController < Suppliers::ApplicationController
|
|
|
|
# GET /products
|
|
# GET /products.json
|
|
def index
|
|
@products = ProductDecorator.decorate(current_supplier.products)
|
|
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.json { render json: @products }
|
|
end
|
|
end
|
|
|
|
# GET /products/1
|
|
# GET /products/1.json
|
|
def show
|
|
@product = ProductDecorator.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json { render json: @product }
|
|
end
|
|
end
|
|
|
|
# GET /products/new
|
|
# GET /products/new.json
|
|
def new
|
|
@product = Product.new
|
|
@product.add_product_category ProductCategory.find_by_supplier_id_and_id!(current_supplier.id, params[:product_category_id]) if params[:product_category_id].present?
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.json { render json: @product }
|
|
end
|
|
end
|
|
|
|
# GET /products/1/edit
|
|
def edit
|
|
@product = Product.find(params[:id])
|
|
end
|
|
|
|
# POST /products
|
|
# POST /products.json
|
|
def create
|
|
@product = Product.new(params[:product])
|
|
@product.supplier = current_supplier
|
|
|
|
respond_to do |format|
|
|
if @product.save
|
|
format.html { redirect_to [:suppliers, @product], notice: t('action.create.successfull', model: Product.model_name.human) }
|
|
format.json { render json: @product, status: :created, location: @product }
|
|
else
|
|
format.html { render action: "new" }
|
|
format.json { render json: @product.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PUT /products/1
|
|
# PUT /products/1.json
|
|
def update
|
|
@product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
|
|
|
respond_to do |format|
|
|
if @product.update_attributes(params[:product])
|
|
format.html { redirect_to [:suppliers, @product], notice: t('action.update.successfull', model: Product.model_name.human) }
|
|
format.json { head :no_content }
|
|
else
|
|
format.html { render action: "edit" }
|
|
format.json { render json: @product.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /products/1
|
|
# DELETE /products/1.json
|
|
def destroy
|
|
@product = Product.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
|
@product.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to suppliers_products_url, notice: t('action.destroy.successfull', model: Product.model_name.human) }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
end
|
|
end
|