updating part2, far from finished
This commit is contained in:
@@ -43,12 +43,12 @@ module Suppliers
|
||||
# POST /products
|
||||
# POST /products.json
|
||||
def create
|
||||
@product = Product.new(params[:product])
|
||||
@product = Product.new(product_params)
|
||||
@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.html { redirect_to [:suppliers, :products], 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" }
|
||||
@@ -63,8 +63,8 @@ module Suppliers
|
||||
@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) }
|
||||
if @product.update_attributes(product_params)
|
||||
format.html { redirect_to [:suppliers, :products], notice: t('action.update.successfull', model: Product.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
@@ -90,5 +90,11 @@ module Suppliers
|
||||
product_categories = ProductCategory.for_supplier_in_time(current_supplier, @time)
|
||||
render json: {categories: product_categories.map(&:to_client_format).select(&:present?)}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def product_params
|
||||
params.require(:product).permit(:name, :code, :price, product_category_ids: [])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user