updating part2, far from finished

This commit is contained in:
2013-12-20 19:22:12 +01:00
parent 748944865d
commit b4c4a15e60
22 changed files with 2779 additions and 62 deletions
@@ -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