Add avatar to product edit form and use recources in routes
This commit is contained in:
parent
552f811fea
commit
4e4f0c32a2
3 changed files with 6 additions and 11 deletions
|
@ -23,8 +23,9 @@ class OrdersController < ApplicationController
|
||||||
if @order.save
|
if @order.save
|
||||||
order_products = order_products_params
|
order_products = order_products_params
|
||||||
order_products.each do |k, v|
|
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
|
end
|
||||||
|
@order.save
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
else
|
else
|
||||||
@order_products = @order.order_products
|
@order_products = @order.order_products
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 col-md-offset-3">
|
<div class="col-md-6 col-md-offset-3">
|
||||||
<%= form_for(@product) do |f| %>
|
<%= form_for(@product) do |f| %>
|
||||||
|
<%= render 'application/errors', model: @product %>
|
||||||
|
|
||||||
<%= f.label :name %>
|
<%= f.label :name %>
|
||||||
<%= f.text_field :name %>
|
<%= f.text_field :name %>
|
||||||
|
@ -13,8 +14,8 @@
|
||||||
<%= f.label :sale_price %>
|
<%= f.label :sale_price %>
|
||||||
<%= f.number_field :sale_price %>
|
<%= f.number_field :sale_price %>
|
||||||
|
|
||||||
<%= f.label :img_path %>
|
<%= f.label :avatar %>
|
||||||
<%= f.text_field :img_path %>
|
<%= f.file_field :avatar %>
|
||||||
|
|
||||||
<%= f.submit "Save changes", class: "btn btn-primary" %>
|
<%= f.submit "Save changes", class: "btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -8,14 +8,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :products
|
resources :products
|
||||||
|
|
||||||
get 'overview' => 'orders#overview'
|
get 'overview' => 'orders#overview'
|
||||||
|
|
||||||
#products
|
|
||||||
get 'products' => 'products#new'
|
|
||||||
post 'products' => 'products#create'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
Loading…
Reference in a new issue