Class: Wco::ProductsController
Instance Method Summary
collapse
#home, #tinymce
#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date
Instance Method Details
#create ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/wco/products_controller.rb', line 8
def create
@product = Wco::Product.new params[:product].permit( :name )
authorize! :create, @product
stripe_product = Stripe::Product.create({ name: @product.name })
flash_notice 'Created stripe product.'
@product.product_id = stripe_product[:id]
if @product.save
flash_notice 'Created wco product.'
else
flash_alert "Cannot create wco product: #{@product.errors.full_messages.join(', ')}."
end
redirect_to action: :index
end
|
#destroy ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/wco/products_controller.rb', line 25
def destroy
@product = Wco::Product.find params[:id]
authorize! :destroy, @product
if @product.destroy
flash_notice 'Deleted Wco::Product'
else
flash_alert "Cannot destroy product: #{@product.errors.fill_messages.join(', ')}."
end
redirect_to action: :index
end
|
#edit ⇒ Object
40
41
42
43
|
# File 'app/controllers/wco/products_controller.rb', line 40
def edit
@product = Wco::Product.find params[:id]
authorize! :edit, @product
end
|
#index ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/controllers/wco/products_controller.rb', line 45
def index
authorize! :index, Wco::Product
@stripe_products = {}
@_stripe_products = Stripe::Product.list().data
@_stripe_prices = Stripe::Price.list().data
@_stripe_products.each do |sp|
@stripe_products[sp[:id]] = sp
@stripe_products[sp[:id]][:prices] ||= {}
end
@_stripe_prices.each do |price|
begin
@stripe_products[price[:product]][:prices][price[:id]] = price
rescue Exception
nil
end
end
@wco_products = Wco::Product.all.includes( :prices )
@wco_products.each do |item|
if @stripe_products[item[:product_id]]
@stripe_products[item[:product_id]][:wco_product] = item
end
end
@wco_prices_hash = {}
@wco_prices = Wco::Price.all
@wco_prices.each do |item|
@wco_prices_hash[item[:price_id]] = item
end
end
|
#new ⇒ Object
82
83
84
85
|
# File 'app/controllers/wco/products_controller.rb', line 82
def new
@product = Wco::Product.new
authorize! :new, @product
end
|
#show ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'app/controllers/wco/products_controller.rb', line 87
def show
authorize! :show, @product
@product = Wco::Product.find params[:id]
respond_to do |format|
format.html
format.json { render 'show.jbuilder', layout: false }
end
end
|
#update ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/controllers/wco/products_controller.rb', line 96
def update
authorize! :edit, @product
@product = Wco::Product.find params[:id]
if @product.update_attributes params[:product].permit!
flash[:notice] = 'Success.'
redirect_to action: :show, id: @product.id
else
flash[:alert] = "No luck: #{@product.errors.full_messages.join(', ')}."
render action: :edit
end
end
|