質問編集履歴
2
説明文がわかりずらかったので修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
機能的には全て完成したのですがビューで表示している画像に対して評価ボタンを押すと違うuser.idがDBに登録されてしまいます。
|
6
6
|
|
7
|
+
ちなみに評価する人のカラムがuser_idで評価される方のカラムがreviewer_idです
|
8
|
+
|
7
9
|
エラーは何も出ていないです。
|
8
10
|
|
9
11
|
自分的に思っている問題点としてはevaluations_controller.rbのindexとcreateで@avataerがとってきている情報が一致していないのが原因だと考えているのですが、そこを一致させる方法がわからないです。
|
1
説明文がわかりずらかったので修正しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
viewに表示されている情報とform_forで送られる情報を一致させたいです
|
test
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
現在ある従業員が他の従業員へ評価をつけるシステム(tinder風)をruby on rails で作っています。
|
2
2
|
|
3
|
+
|
4
|
+
|
3
|
-
|
5
|
+
機能的には全て完成したのですがビューで表示している画像に対して評価ボタンを押すと違うuser.idがDBに登録されてしまいます。
|
6
|
+
|
4
|
-
|
7
|
+
エラーは何も出ていないです。
|
8
|
+
|
5
|
-
|
9
|
+
自分的に思っている問題点としてはevaluations_controller.rbのindexとcreateで@avataerがとってきている情報が一致していないのが原因だと考えているのですが、そこを一致させる方法がわからないです。
|
6
|
-
|
7
|
-
|
10
|
+
|
8
|
-
|
9
|
-
|
11
|
+
ぜひ教えてもらえると助かります。
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
21
|
-
|
19
|
+
evaluations_controller.rb
|
20
|
+
|
21
|
+
```
|
22
22
|
|
23
23
|
class EvaluationsController < ApplicationController
|
24
24
|
|
@@ -42,6 +42,8 @@
|
|
42
42
|
|
43
43
|
def create
|
44
44
|
|
45
|
+
@avatar = User.order("RAND()").first
|
46
|
+
|
45
47
|
@evaluation = Evaluation.new(create_params)
|
46
48
|
|
47
49
|
# binding.pry
|
@@ -52,7 +54,7 @@
|
|
52
54
|
|
53
55
|
|
54
56
|
|
55
|
-
redirect_to
|
57
|
+
redirect_back(fallback_location: user_evaluations_path(current_user, @avatar))
|
56
58
|
|
57
59
|
end
|
58
60
|
|
@@ -62,23 +64,25 @@
|
|
62
64
|
|
63
65
|
def create_params
|
64
66
|
|
65
|
-
params.require(:evaluation).permit(:user_id
|
67
|
+
params.require(:evaluation).permit(:rate).merge(reviewer_id: @avatar.id, user_id: current_user.id)
|
66
|
-
|
68
|
+
|
67
|
-
end
|
69
|
+
end
|
68
|
-
|
70
|
+
|
69
|
-
end
|
71
|
+
end
|
70
|
-
|
71
|
-
|
72
|
-
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
73
|
-
```
|
77
|
+
```
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
81
|
-
|
83
|
+
users_controller.rb
|
84
|
+
|
85
|
+
```
|
82
86
|
|
83
87
|
class UsersController < ApplicationController
|
84
88
|
|
@@ -94,12 +98,16 @@
|
|
94
98
|
|
95
99
|
def edit
|
96
100
|
|
101
|
+
@user = current_user
|
102
|
+
|
97
103
|
end
|
98
104
|
|
99
105
|
|
100
106
|
|
101
107
|
def update
|
102
108
|
|
109
|
+
@user = current_user
|
110
|
+
|
103
111
|
current_user.update(update_params)
|
104
112
|
|
105
113
|
end
|
@@ -120,15 +128,17 @@
|
|
120
128
|
|
121
129
|
|
122
130
|
|
131
|
+
|
132
|
+
|
123
|
-
```
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
|
124
|
-
|
137
|
+
evaluationsの
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
138
|
+
|
131
|
-
|
139
|
+
index.html.erb
|
140
|
+
|
141
|
+
```
|
132
142
|
|
133
143
|
<div class="posting_form top_content">
|
134
144
|
|
@@ -154,12 +164,14 @@
|
|
154
164
|
|
155
165
|
</header>
|
156
166
|
|
157
|
-
<%= form_for
|
167
|
+
<%= form_for [@avatar, @evaluation] do |f| %>
|
158
168
|
|
159
169
|
<div class="field">
|
160
170
|
|
161
171
|
<div class="profile_edit">
|
162
172
|
|
173
|
+
<%= hidden_field_tag :reviewer_id, @avatar.id %>
|
174
|
+
|
163
175
|
<%= f.radio_button :rate, :so_good, checked: "checked" %>
|
164
176
|
|
165
177
|
<%= f.label :so_good %>
|
@@ -168,6 +180,8 @@
|
|
168
180
|
|
169
181
|
<div class="profile_edit">
|
170
182
|
|
183
|
+
<%= hidden_field_tag :reviewer_id, @avatar.id %>
|
184
|
+
|
171
185
|
<%= f.radio_button :rate, :good %>
|
172
186
|
|
173
187
|
<%= f.label :good %>
|
@@ -176,6 +190,8 @@
|
|
176
190
|
|
177
191
|
<div class="profile_edit">
|
178
192
|
|
193
|
+
<%= hidden_field_tag :reviewer_id, @avatar.id %>
|
194
|
+
|
179
195
|
<%= f.radio_button :rate, :bad %>
|
180
196
|
|
181
197
|
<%= f.label :bad %>
|
@@ -184,6 +200,8 @@
|
|
184
200
|
|
185
201
|
<div class="profile_edit">
|
186
202
|
|
203
|
+
<%= hidden_field_tag :reviewer_id, @avatar.id %>
|
204
|
+
|
187
205
|
<%= f.radio_button :rate, :so_bad %>
|
188
206
|
|
189
207
|
<%= f.label :so_bad %>
|
@@ -196,47 +214,17 @@
|
|
196
214
|
|
197
215
|
<% end %>
|
198
216
|
|
217
|
+
|
218
|
+
|
199
|
-
```
|
219
|
+
```
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
209
|
-
|
225
|
+
create_evaluations.rb
|
210
|
-
|
211
|
-
|
226
|
+
|
212
|
-
|
213
|
-
devise_for :users
|
214
|
-
|
215
|
-
resources :evaluations, only: [:index ,:create]
|
216
|
-
|
217
|
-
resources :users, only: [:edit, :update]
|
218
|
-
|
219
|
-
resources :users, only: :show do
|
220
|
-
|
221
|
-
resources :evaluations, only: [:index ,:create]
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
root to: "top#index"
|
226
|
-
|
227
|
-
end
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
```
|
227
|
+
```
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
```ruby:_create_evaluations.rb
|
240
228
|
|
241
229
|
class CreateEvaluations < ActiveRecord::Migration[5.0]
|
242
230
|
|
@@ -248,6 +236,8 @@
|
|
248
236
|
|
249
237
|
t.integer :rate
|
250
238
|
|
239
|
+
t.integer :reviewer_id
|
240
|
+
|
251
241
|
t.timestamps
|
252
242
|
|
253
243
|
end
|
@@ -256,6 +246,26 @@
|
|
256
246
|
|
257
247
|
end
|
258
248
|
|
259
|
-
|
260
|
-
|
261
|
-
```
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
evaluation.rb
|
254
|
+
|
255
|
+
```
|
256
|
+
|
257
|
+
class Evaluation < ApplicationRecord
|
258
|
+
|
259
|
+
belongs_to :user
|
260
|
+
|
261
|
+
belongs_to :reviewer, class_name: 'User', foreign_key: :reviewer_id
|
262
|
+
|
263
|
+
validates_presence_of :user_id, :rate ,:reviewer_id
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
enum rate: {so_good:1, good:2, bad:3 ,so_bad:4}
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
```
|