質問編集履歴
2
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -323,3 +323,81 @@
|
|
323
323
|
end
|
324
324
|
|
325
325
|
```
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
**posts/show.html**
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
|
333
|
+
<div class="main posts-show">
|
334
|
+
|
335
|
+
<div class="container">
|
336
|
+
|
337
|
+
<div class="posts-show-item">
|
338
|
+
|
339
|
+
<div class="post-user-name">
|
340
|
+
|
341
|
+
<img src="<%= "/#{@user.image_name}" %>">
|
342
|
+
|
343
|
+
<%= link_to(@user.name, "/users/#{@user.id}") %>
|
344
|
+
|
345
|
+
</div>
|
346
|
+
|
347
|
+
<p>
|
348
|
+
|
349
|
+
<%= @post.content %>
|
350
|
+
|
351
|
+
</p>
|
352
|
+
|
353
|
+
<div class="post-time">
|
354
|
+
|
355
|
+
<%= @post.created_at %>
|
356
|
+
|
357
|
+
</div>
|
358
|
+
|
359
|
+
<% if Like.find_by(user_id: @current_user.id, post_id: @post.id) %>
|
360
|
+
|
361
|
+
<%= link_to("/likes/#{@post.id}/destroy", {method: "post"}) do %>
|
362
|
+
|
363
|
+
<span class="fa fa-heart like-btn-unlike"></span>
|
364
|
+
|
365
|
+
<% end %>
|
366
|
+
|
367
|
+
<% else %>
|
368
|
+
|
369
|
+
<%= link_to("/likes/#{@post.id}/create", {method: "post"}) do %>
|
370
|
+
|
371
|
+
<span class="fa fa-heart like-btn"></span>
|
372
|
+
|
373
|
+
<% end %>
|
374
|
+
|
375
|
+
<% end %>
|
376
|
+
|
377
|
+
<!-- 変数@likes_countを表示してください -->
|
378
|
+
|
379
|
+
<%= @likes_count %>
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
<% if @post.user_id == @current_user.id %>
|
384
|
+
|
385
|
+
<div class="post-menus">
|
386
|
+
|
387
|
+
<%= link_to("編集", "/posts/#{@post.id}/edit") %>
|
388
|
+
|
389
|
+
<%= link_to("削除", "/posts/#{@post.id}/destroy", {method: "post"}) %>
|
390
|
+
|
391
|
+
</div>
|
392
|
+
|
393
|
+
<% end %>
|
394
|
+
|
395
|
+
</div>
|
396
|
+
|
397
|
+
</div>
|
398
|
+
|
399
|
+
</div>
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
```
|
1
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -241,3 +241,85 @@
|
|
241
241
|
</div>
|
242
242
|
|
243
243
|
```
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
**routes.rb**
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
|
251
|
+
Rails.application.routes.draw do
|
252
|
+
|
253
|
+
get 'users/index'
|
254
|
+
|
255
|
+
#get 'home/top'
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
get "login" => "users#login_form"
|
260
|
+
|
261
|
+
post "login" => "users#login"
|
262
|
+
|
263
|
+
post "logout" => "users#logout"
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
post "users/:id/update" => "users#update"
|
268
|
+
|
269
|
+
get "users/:id/edit" => "users#edit"
|
270
|
+
|
271
|
+
post "users/create" => "users#create"
|
272
|
+
|
273
|
+
get "signup" => "users#new"
|
274
|
+
|
275
|
+
get "users/index" => "users#index"
|
276
|
+
|
277
|
+
get "users/:id" => "users#show"
|
278
|
+
|
279
|
+
post "users/:id/destroy" => "users#destroy"
|
280
|
+
|
281
|
+
post "likes/:id"=>"posts#likes"
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
get "posts/index" => "posts#index"
|
286
|
+
|
287
|
+
get "posts/new" => "posts#new"
|
288
|
+
|
289
|
+
get "posts/:id" => "posts#show"
|
290
|
+
|
291
|
+
post "posts/create" => "posts#create"
|
292
|
+
|
293
|
+
get "posts/:id/edit" => "posts#edit"
|
294
|
+
|
295
|
+
post "posts/:id/update" => "posts#update"
|
296
|
+
|
297
|
+
post "posts/:id/destroy" => "posts#destroy"
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
get "/" => "home#top"
|
310
|
+
|
311
|
+
get "/about" => "home#about"
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
match '*unmatched',to: 'application#route_not_found',via: :all
|
320
|
+
|
321
|
+
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
```
|