diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb
index b37d537..421d597 100644
--- a/app/controllers/orders_controller.rb
+++ b/app/controllers/orders_controller.rb
@@ -23,8 +23,9 @@ class OrdersController < ApplicationController
if @order.save
order_products = order_products_params
order_products.each do |k, v|
- @order.order_products.create(product: Product.find(k), count: v[:count]) if v[:count].to_i > 0
+ @order.order_products.build(product: Product.find(k), count: v[:count]) if v[:count].to_i > 0
end
+ @order.save
redirect_to root_path
else
@order_products = @order.order_products
diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb
index ff64ced..b3a8bb7 100644
--- a/app/views/products/edit.html.erb
+++ b/app/views/products/edit.html.erb
@@ -3,6 +3,7 @@
<%= form_for(@product) do |f| %>
+ <%= render 'application/errors', model: @product %>
<%= f.label :name %>
<%= f.text_field :name %>
@@ -13,8 +14,8 @@
<%= f.label :sale_price %>
<%= f.number_field :sale_price %>
- <%= f.label :img_path %>
- <%= f.text_field :img_path %>
+ <%= f.label :avatar %>
+ <%= f.file_field :avatar %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index f4dac29..a049993 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -8,14 +8,7 @@ Rails.application.routes.draw do
resources :products
- get 'overview' => 'orders#overview'
-
- #products
- get 'products' => 'products#new'
- post 'products' => 'products#create'
-
-
-
+ get 'overview' => 'orders#overview'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".