-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathproducts_controller.rb
More file actions
60 lines (44 loc) · 981 Bytes
/
products_controller.rb
File metadata and controls
60 lines (44 loc) · 981 Bytes
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
59
60
class Admin::ProductsController < ApplicationController
before_action :authenticate_user!
before_action :admin_required
def new
@product = Product.new
@photo = @product.photos.new
end
def create
@product = Product.new(product_params)
if @product.save
redirect_to admin_products_path
else
render :new
end
end
def index
@products = Product.all
@photos = Photo.all
end
def show
@product = Product.find(params[:id])
end
def edit
@product = Product.find(params[:id])
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
flash[:success] = "Delete Successfully!."
redirect_to admin_products_path
end
private
def product_params
params.require(:product).permit(:title, :description,:quantity, :price, :photos_attributes => [:image])
end
end