Class: ProductsController
Instance Attribute Summary
#req, #res
Instance Method Summary
collapse
#boolean_param, #csrf_token, #delete_all_images_from_content, #delete_from_storage, #initialize, #params, #redirect_to, #render, #session, #validate!
Instance Method Details
#create ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/products_controller.rb', line 19
def create
data = params['product']
@product = Product.new(data)
if @product.save
redirect_to '/dashboard/products'
else
render 'cms/products_form'
end
end
|
#destroy ⇒ Object
43
44
45
46
47
|
# File 'app/controllers/products_controller.rb', line 43
def destroy
@product = Product[params['id']]
@product.destroy
redirect_to '/dashboard/products'
end
|
#edit ⇒ Object
29
30
31
32
|
# File 'app/controllers/products_controller.rb', line 29
def edit
@product = Product[params['id']]
render 'cms/products_form'
end
|
#index ⇒ Object
4
5
6
7
8
9
10
11
12
|
# File 'app/controllers/products_controller.rb', line 4
def index
if req.path.start_with?('/dashboard')
@products = Product.order(Sequel.desc(:created_at)).all
render 'cms/products_index'
else
@products = Product.where(is_active: true).order(Sequel.desc(:created_at)).all
render 'products_index', title: "Shop - One-For-All"
end
end
|
#new ⇒ Object
14
15
16
17
|
# File 'app/controllers/products_controller.rb', line 14
def new
@product = Product.new
render 'cms/products_form'
end
|
#show ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'app/controllers/products_controller.rb', line 49
def show
@product = Product.find(slug: params['slug'], is_active: true)
if @product
render 'product_show', title: "#{@product.name} - One-For-All"
else
@res.status = 404
render 'error', message: "Product not found."
end
end
|
#update ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'app/controllers/products_controller.rb', line 34
def update
@product = Product[params['id']]
if @product.update(params['product'])
redirect_to '/dashboard/products'
else
render 'cms/products_form'
end
end
|