質問編集履歴
1
articles/show\.html\.erbとartcles_controllerを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -137,3 +137,163 @@
|
|
137
137
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
138
138
|
|
139
139
|
開発環境:Ruby on Rail 5.0.0.1
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
###追記情報(該当ソース)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
・ビュー(articles/show.html.erb)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
・・・
|
154
|
+
|
155
|
+
<section>
|
156
|
+
|
157
|
+
<div class="title">
|
158
|
+
|
159
|
+
<h2>コメント</h2>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<% if logged_in? %>
|
164
|
+
|
165
|
+
<div class="row">
|
166
|
+
|
167
|
+
<aside class="col-md-4">
|
168
|
+
|
169
|
+
<section class="cooment_form">
|
170
|
+
|
171
|
+
<%= render 'shared/comment_form' %>
|
172
|
+
|
173
|
+
</section>
|
174
|
+
|
175
|
+
</aside>
|
176
|
+
|
177
|
+
</div>
|
178
|
+
|
179
|
+
<% else %>
|
180
|
+
|
181
|
+
<div></div>
|
182
|
+
|
183
|
+
<% end %>
|
184
|
+
|
185
|
+
<%= render 'shared/feed' %>
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
</section>
|
190
|
+
|
191
|
+
・・・
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
・ビュー(shared/comment_form)
|
196
|
+
|
197
|
+
```Ruby
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<%= form_for(@comment) do |f| %>
|
202
|
+
|
203
|
+
<%= render 'shared/error_messages', object: f.object %>
|
204
|
+
|
205
|
+
<div class="field">
|
206
|
+
|
207
|
+
<%= f.text_area :content, placeholder: "コメントを入力する" %>
|
208
|
+
|
209
|
+
</div>
|
210
|
+
|
211
|
+
<%= f.submit "Post", class: "btn btn-primary" %>
|
212
|
+
|
213
|
+
<% end %>
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
・ビュー(shared/feed)
|
218
|
+
|
219
|
+
```Ruby
|
220
|
+
|
221
|
+
<%if @feed_items.any? %>
|
222
|
+
|
223
|
+
<%= render @feed_items %>
|
224
|
+
|
225
|
+
<%= will_paginate @feed_items %>
|
226
|
+
|
227
|
+
<% end %>
|
228
|
+
|
229
|
+
```
|
230
|
+
|
231
|
+
・コントローラー(artcles/controller)
|
232
|
+
|
233
|
+
```Ruby
|
234
|
+
|
235
|
+
class ArticlesController < ApplicationController
|
236
|
+
|
237
|
+
before_action :comment_feed, only:[:show, :comment]
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
def show
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
def search
|
248
|
+
|
249
|
+
@articles = Article.paginate(page: params[:page])
|
250
|
+
|
251
|
+
@categories = Category.all
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
def new
|
258
|
+
|
259
|
+
@article = Article.new(create_params)
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
private
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
def article_params
|
270
|
+
|
271
|
+
params.require(:space).permit(:title, :content)
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
def set_article
|
278
|
+
|
279
|
+
@article = Article.find(params[:id])
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
def comment_feed
|
286
|
+
|
287
|
+
if logged_in?
|
288
|
+
|
289
|
+
@comment = current_user.comments.build
|
290
|
+
|
291
|
+
@feed_items = current_user.feed.paginate(page: params[:page])
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
```
|