質問編集履歴
6
change
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,242 +1,6 @@
|
|
1
1
|
![イメージ説明](1645e124256f0e43df12a31b13a7f63d.png)
|
2
2
|
|
3
3
|
|
4
|
-
|
5
|
-
###likes.html.erb
|
6
|
-
|
7
|
-
```ここに言語を入力
|
8
|
-
|
9
|
-
<%= render "partial/navbar" %>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
<div class="user-show">
|
14
|
-
|
15
|
-
<div class="container">
|
16
|
-
|
17
|
-
<div class="row">
|
18
|
-
|
19
|
-
<div class="col-lg-3 col-md-4">
|
20
|
-
|
21
|
-
<div class="user-profile row-space-4 text-center">
|
22
|
-
|
23
|
-
<% if current_user.image %>
|
24
|
-
|
25
|
-
<img src="<%= "/user_images/#{@user.image}" %>" class="profile-full img-circle">
|
26
|
-
|
27
|
-
<% else %>
|
28
|
-
|
29
|
-
<p><%= link_to "プロフィール画像を追加する", edit_user_path(current_user), class:"profile-full img-circle" %></p>
|
30
|
-
|
31
|
-
<% end %>
|
32
|
-
|
33
|
-
</div>
|
34
|
-
|
35
|
-
</div>
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
<div class="col-lg-9 col-md-8 col-sm-12">
|
40
|
-
|
41
|
-
<div class="user-title">
|
42
|
-
|
43
|
-
<% if current_user.name %>
|
44
|
-
|
45
|
-
<h1><%= @user.name%></h1>
|
46
|
-
|
47
|
-
<% else %>
|
48
|
-
|
49
|
-
<p><%= link_to "ユーザー名を追加して下さい", edit_user_path(current_user) %></p>
|
50
|
-
|
51
|
-
<% end %>
|
52
|
-
|
53
|
-
<% if current_user.id == @user.id %>
|
54
|
-
|
55
|
-
<%= link_to "プロフィール編集", edit_user_path(current_user), class: "btn btn-default btn-full" %>
|
56
|
-
|
57
|
-
<%= link_to "ログアウト", destroy_user_session_path, method: :delete, class: "btn btn-default btn-full" %>
|
58
|
-
|
59
|
-
<% end %>
|
60
|
-
|
61
|
-
</div>
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
<div class="user-description">
|
66
|
-
|
67
|
-
自己紹介:
|
68
|
-
|
69
|
-
<% if current_user.description %>
|
70
|
-
|
71
|
-
<%= @user.description %>
|
72
|
-
|
73
|
-
<% else %>
|
74
|
-
|
75
|
-
自己紹介文が空白です。<%= link_to "自己紹介を書く", edit_user_path(current_user) %>
|
76
|
-
|
77
|
-
<% end %>
|
78
|
-
|
79
|
-
</div>
|
80
|
-
|
81
|
-
</div>
|
82
|
-
|
83
|
-
</div>
|
84
|
-
|
85
|
-
</div>
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
<ul class="user-tabs">
|
92
|
-
|
93
|
-
<li><%= link_to("質問", "/users/#{@user.id}") %></li>
|
94
|
-
|
95
|
-
<li class="active"><%= link_to("お気に入り", "/users/#{@user.id}/likes") %></li>
|
96
|
-
|
97
|
-
</ul>
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
<br>
|
102
|
-
|
103
|
-
<hr>
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
<% @likes.each do |like| %>
|
112
|
-
|
113
|
-
<%
|
114
|
-
|
115
|
-
question = User.find_by(id: like.question_id)
|
116
|
-
|
117
|
-
continue if question.nil?
|
118
|
-
|
119
|
-
%>
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
<div class="card">
|
124
|
-
|
125
|
-
<div class="card-block">
|
126
|
-
|
127
|
-
<h4 class="card-title">
|
128
|
-
|
129
|
-
<img src="<%= "/user_images/#{question.user.image}" %>" class="img-circle profile-1">
|
130
|
-
|
131
|
-
</h4>
|
132
|
-
|
133
|
-
<h6 class="card-subtitle mb-2 text-muted">
|
134
|
-
|
135
|
-
<%= link_to(question.user.name, "/users/#{question.user.id}") %>
|
136
|
-
|
137
|
-
</h6>
|
138
|
-
|
139
|
-
<hr>
|
140
|
-
|
141
|
-
<p class="card-text">
|
142
|
-
|
143
|
-
<%= link_to(question.content, "/questions/#{question.id}") %>
|
144
|
-
|
145
|
-
</p>
|
146
|
-
|
147
|
-
<p class="card-link">
|
148
|
-
|
149
|
-
<%= question.created_at.strftime('%Y/%m/%d %H:%M') %>
|
150
|
-
|
151
|
-
</p>
|
152
|
-
|
153
|
-
</div>
|
154
|
-
|
155
|
-
</div>
|
156
|
-
|
157
|
-
<% end %>
|
158
|
-
|
159
|
-
<% end %>
|
160
|
-
|
161
|
-
</div>
|
162
|
-
|
163
|
-
</div>
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
```
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
###user_controller.rb
|
172
|
-
|
173
|
-
```ここに言語を入力
|
174
|
-
|
175
|
-
class UsersController < ApplicationController
|
176
|
-
|
177
|
-
def likes
|
178
|
-
|
179
|
-
@user = User.find_by(id: params[:id])
|
180
|
-
|
181
|
-
@likes = Like.where(user_id: @user.id)
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
```
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
どの部分がエラーになっているのでしょうか?
|
190
|
-
|
191
|
-
また、どう修正したら良いのでしょうか?
|
192
|
-
|
193
|
-
教えてください!
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
###model
|
198
|
-
|
199
|
-
**user.rb**
|
200
|
-
|
201
|
-
```ここに言語を入力
|
202
|
-
|
203
|
-
class User < ApplicationRecord
|
204
|
-
|
205
|
-
has_many :questions
|
206
|
-
|
207
|
-
has_many :answers
|
208
|
-
|
209
|
-
has_many :likes
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
```
|
214
|
-
|
215
|
-
**like.rb**
|
216
|
-
|
217
|
-
```ここに言語を入力
|
218
|
-
|
219
|
-
class Like < ApplicationRecord
|
220
|
-
|
221
|
-
belongs_to :question
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
|
-
```
|
226
|
-
|
227
|
-
**question.rb**
|
228
|
-
|
229
|
-
```ここに言語を入力
|
230
|
-
|
231
|
-
class Question < ApplicationRecord
|
232
|
-
|
233
|
-
belongs_to :user
|
234
|
-
|
235
|
-
has_many :answers
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
```
|
240
4
|
|
241
5
|
|
242
6
|
|
5
like add
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,9 +6,117 @@
|
|
6
6
|
|
7
7
|
```ここに言語を入力
|
8
8
|
|
9
|
+
<%= render "partial/navbar" %>
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<div class="user-show">
|
14
|
+
|
15
|
+
<div class="container">
|
16
|
+
|
17
|
+
<div class="row">
|
18
|
+
|
19
|
+
<div class="col-lg-3 col-md-4">
|
20
|
+
|
21
|
+
<div class="user-profile row-space-4 text-center">
|
22
|
+
|
23
|
+
<% if current_user.image %>
|
24
|
+
|
25
|
+
<img src="<%= "/user_images/#{@user.image}" %>" class="profile-full img-circle">
|
26
|
+
|
27
|
+
<% else %>
|
28
|
+
|
29
|
+
<p><%= link_to "プロフィール画像を追加する", edit_user_path(current_user), class:"profile-full img-circle" %></p>
|
30
|
+
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
<div class="col-lg-9 col-md-8 col-sm-12">
|
40
|
+
|
41
|
+
<div class="user-title">
|
42
|
+
|
43
|
+
<% if current_user.name %>
|
44
|
+
|
45
|
+
<h1><%= @user.name%></h1>
|
46
|
+
|
47
|
+
<% else %>
|
48
|
+
|
49
|
+
<p><%= link_to "ユーザー名を追加して下さい", edit_user_path(current_user) %></p>
|
50
|
+
|
51
|
+
<% end %>
|
52
|
+
|
53
|
+
<% if current_user.id == @user.id %>
|
54
|
+
|
55
|
+
<%= link_to "プロフィール編集", edit_user_path(current_user), class: "btn btn-default btn-full" %>
|
56
|
+
|
57
|
+
<%= link_to "ログアウト", destroy_user_session_path, method: :delete, class: "btn btn-default btn-full" %>
|
58
|
+
|
59
|
+
<% end %>
|
60
|
+
|
61
|
+
</div>
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
<div class="user-description">
|
66
|
+
|
67
|
+
自己紹介:
|
68
|
+
|
69
|
+
<% if current_user.description %>
|
70
|
+
|
71
|
+
<%= @user.description %>
|
72
|
+
|
73
|
+
<% else %>
|
74
|
+
|
75
|
+
自己紹介文が空白です。<%= link_to "自己紹介を書く", edit_user_path(current_user) %>
|
76
|
+
|
77
|
+
<% end %>
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
</div>
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
<ul class="user-tabs">
|
92
|
+
|
93
|
+
<li><%= link_to("質問", "/users/#{@user.id}") %></li>
|
94
|
+
|
95
|
+
<li class="active"><%= link_to("お気に入り", "/users/#{@user.id}/likes") %></li>
|
96
|
+
|
97
|
+
</ul>
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
<br>
|
102
|
+
|
103
|
+
<hr>
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
9
|
-
<% @likes.each do |like| %>
|
111
|
+
<% @likes.each do |like| %>
|
112
|
+
|
10
|
-
|
113
|
+
<%
|
114
|
+
|
11
|
-
|
115
|
+
question = User.find_by(id: like.question_id)
|
116
|
+
|
117
|
+
continue if question.nil?
|
118
|
+
|
119
|
+
%>
|
12
120
|
|
13
121
|
|
14
122
|
|
@@ -46,7 +154,15 @@
|
|
46
154
|
|
47
155
|
</div>
|
48
156
|
|
49
|
-
<% end %>
|
157
|
+
<% end %>
|
158
|
+
|
159
|
+
<% end %>
|
160
|
+
|
161
|
+
</div>
|
162
|
+
|
163
|
+
</div>
|
164
|
+
|
165
|
+
|
50
166
|
|
51
167
|
```
|
52
168
|
|
4
add
test
CHANGED
File without changes
|
test
CHANGED
@@ -121,3 +121,11 @@
|
|
121
121
|
end
|
122
122
|
|
123
123
|
```
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
###やりたいこと
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
ユーザーがlikeした、questionを全て取り出し、表示したいのですが、うまく行きません。
|
3
change model
test
CHANGED
File without changes
|
test
CHANGED
@@ -100,7 +100,7 @@
|
|
100
100
|
|
101
101
|
```ここに言語を入力
|
102
102
|
|
103
|
-
class
|
103
|
+
class Like < ApplicationRecord
|
104
104
|
|
105
105
|
belongs_to :question
|
106
106
|
|
2
add model class
test
CHANGED
File without changes
|
test
CHANGED
@@ -84,11 +84,15 @@
|
|
84
84
|
|
85
85
|
```ここに言語を入力
|
86
86
|
|
87
|
+
class User < ApplicationRecord
|
88
|
+
|
87
89
|
has_many :questions
|
88
90
|
|
89
91
|
has_many :answers
|
90
92
|
|
91
93
|
has_many :likes
|
94
|
+
|
95
|
+
end
|
92
96
|
|
93
97
|
```
|
94
98
|
|
@@ -96,7 +100,11 @@
|
|
96
100
|
|
97
101
|
```ここに言語を入力
|
98
102
|
|
103
|
+
class like < ApplicationRecord
|
104
|
+
|
99
105
|
belongs_to :question
|
106
|
+
|
107
|
+
end
|
100
108
|
|
101
109
|
```
|
102
110
|
|
@@ -104,8 +112,12 @@
|
|
104
112
|
|
105
113
|
```ここに言語を入力
|
106
114
|
|
115
|
+
class Question < ApplicationRecord
|
116
|
+
|
107
117
|
belongs_to :user
|
108
118
|
|
109
119
|
has_many :answers
|
110
120
|
|
121
|
+
end
|
122
|
+
|
111
123
|
```
|
1
modelの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -75,3 +75,37 @@
|
|
75
75
|
また、どう修正したら良いのでしょうか?
|
76
76
|
|
77
77
|
教えてください!
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
###model
|
82
|
+
|
83
|
+
**user.rb**
|
84
|
+
|
85
|
+
```ここに言語を入力
|
86
|
+
|
87
|
+
has_many :questions
|
88
|
+
|
89
|
+
has_many :answers
|
90
|
+
|
91
|
+
has_many :likes
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
**like.rb**
|
96
|
+
|
97
|
+
```ここに言語を入力
|
98
|
+
|
99
|
+
belongs_to :question
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
**question.rb**
|
104
|
+
|
105
|
+
```ここに言語を入力
|
106
|
+
|
107
|
+
belongs_to :user
|
108
|
+
|
109
|
+
has_many :answers
|
110
|
+
|
111
|
+
```
|