-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog.diff
More file actions
143 lines (140 loc) · 4.08 KB
/
Copy pathlog.diff
File metadata and controls
143 lines (140 loc) · 4.08 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
diff --git a/app/assets/javascripts/admin.coffee b/app/assets/javascripts/admin.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/admin.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss
new file mode 100644
index 0000000..6b55735
--- /dev/null
+++ b/app/assets/stylesheets/admin.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the admin controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/admin/orders_controller.rb b/app/controllers/admin/orders_controller.rb
index ffbc74d..1afa41b 100644
--- a/app/controllers/admin/orders_controller.rb
+++ b/app/controllers/admin/orders_controller.rb
@@ -1,7 +1,4 @@
class Admin::OrdersController < ApplicationController
- layout "admin"
- before_action :authenticate_user!
- before_action :admin_required
def index
@orders = Order.order("id DESC")
diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb
index 7ee9796..28e50eb 100644
--- a/app/controllers/admin/products_controller.rb
+++ b/app/controllers/admin/products_controller.rb
@@ -1,8 +1,5 @@
-class Admin::ProductsController < ApplicationController
- before_action :authenticate_user!
- before_action :admin_required
+class Admin::ProductsController < AdminController
- layout "admin"
def index
@products = Product.all
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
new file mode 100644
index 0000000..a16eb7f
--- /dev/null
+++ b/app/controllers/admin_controller.rb
@@ -0,0 +1,6 @@
+class AdminController < ApplicationController
+ before_action :authenticate_user!
+ before_action :admin_required
+
+ layout "admin"
+end
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
new file mode 100644
index 0000000..d5c6d35
--- /dev/null
+++ b/app/helpers/admin_helper.rb
@@ -0,0 +1,2 @@
+module AdminHelper
+end
diff --git a/app/models/concern.rb b/app/models/concern.rb
new file mode 100644
index 0000000..7f2d662
--- /dev/null
+++ b/app/models/concern.rb
@@ -0,0 +1,5 @@
+module Concern
+ def self.table_name_prefix
+ 'concern_'
+ end
+end
diff --git a/app/models/concerns.rb b/app/models/concerns.rb
new file mode 100644
index 0000000..bbcea32
--- /dev/null
+++ b/app/models/concerns.rb
@@ -0,0 +1,5 @@
+module Concerns
+ def self.table_name_prefix
+ 'concerns_'
+ end
+end
diff --git a/app/models/concerns/tokenable.rb b/app/models/concerns/tokenable.rb
new file mode 100644
index 0000000..2bee68a
--- /dev/null
+++ b/app/models/concerns/tokenable.rb
@@ -0,0 +1,13 @@
+module Tokenable
+
+ extend ActiveSupport::Concern
+
+ included do
+ before_create :generate_token
+ end
+
+
+ def generate_token
+ self.token = SecureRandom.uuid
+ end
+end
\ No newline at end of file
diff --git a/app/models/order.rb b/app/models/order.rb
index 045e8d6..5515e08 100644
--- a/app/models/order.rb
+++ b/app/models/order.rb
@@ -1,13 +1,15 @@
class Order < ApplicationRecord
- before_create :generate_token
+ include Tokenable
+
+ # before_create :generate_token
belongs_to :user
has_many :product_lists
validates :first_name, presence: true
validates :last_name, presence: true
validates :phonenumber, presence: true
- def generate_token
- self.token = SecureRandom.uuid
- end
+ # def generate_token
+ # self.token = SecureRandom.uuid
+ # end
def set_payment_with!(method)
self.update_columns(payment_method: method)
end
diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb
new file mode 100644
index 0000000..54f3be4
--- /dev/null
+++ b/test/controllers/admin_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AdminControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end