-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathproducts_controller.rb
More file actions
58 lines (44 loc) · 1.07 KB
/
products_controller.rb
File metadata and controls
58 lines (44 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Admin::ProductsController < ApplicationController
before_action :authenticate_user!
before_action :admin_required
def index
@products = Product.all
end
def new
@product = Product.new
@photo = @product.photos.new
end
def show
@product = Product.find(params[:id])
end
def edit
@product = Product.find(params[:id])
@photos = @product.photos
end
def update
@product = Product.find(params[:id])
if @product.update(product_params)
redirect_to admin_products_path
else
render :edit
end
end
def destroy
@product = Product.find(params[:id])
@product.destroy!
redirect_to admin_products_path
end
def create
@product = Product.new(product_params)
if @product.save
redirect_to admin_products_path
else
render :new
end
end
private
def product_params
#params.require(:product).permit(:title,:description,:quantity, :price, :image)
params.require(:product).permit(:title,:description,:quantity, :price, :photos_attributes => [:image])
end
end