質問編集履歴
3
名称変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
一覧ページにおける
|
13
|
+
一覧ページにおけるreview_idの取得の仕方
|
14
14
|
|
15
15
|
|
16
16
|
|
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
ルーティングにおけるコードの書き方 ー
|
22
22
|
|
23
|
-
like と
|
23
|
+
like と review がルーティングで独立してるのは気がついているのですが、
|
24
24
|
|
25
25
|
できれば resources を使いたいと考えています。
|
26
26
|
|
2
review controller の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,6 +62,70 @@
|
|
62
62
|
|
63
63
|
```
|
64
64
|
|
65
|
+
```ruby
|
66
|
+
|
67
|
+
class ReviewsController < ApplicationController
|
68
|
+
|
69
|
+
before_action :authenticate_user!
|
70
|
+
|
71
|
+
before_action :move_to_signin
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
def index
|
76
|
+
|
77
|
+
@reviews = Review.all
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
def new
|
84
|
+
|
85
|
+
@review = Review.new
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def create
|
92
|
+
|
93
|
+
@review = Review.new(review_params)
|
94
|
+
|
95
|
+
if @review.save
|
96
|
+
|
97
|
+
redirect_to reviews_path
|
98
|
+
|
99
|
+
else
|
100
|
+
|
101
|
+
render :new
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
def show
|
110
|
+
|
111
|
+
@review = Review.find_by(id: params[:id])
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def review_params
|
120
|
+
|
121
|
+
params.require(:review).permit(:title, :content, :image).merge(user_id: current_user.id)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
```
|
128
|
+
|
65
129
|
```haml
|
66
130
|
|
67
131
|
-# index.html.haml
|
1
ファイルの省略無し
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,17 +28,17 @@
|
|
28
28
|
|
29
29
|
### 該当のソースコード
|
30
30
|
|
31
|
-
関係のないところは省略します
|
32
|
-
|
33
31
|
```ruby
|
34
32
|
|
35
33
|
class LikesController < ApplicationController
|
36
34
|
|
37
35
|
def create
|
38
36
|
|
39
|
-
@like = Like.new(user_id: current_user.id,
|
37
|
+
@like = Like.new(user_id: current_user.id, review_id: id)
|
40
38
|
|
41
39
|
@like.save
|
40
|
+
|
41
|
+
redirect_to reviews_path
|
42
42
|
|
43
43
|
end
|
44
44
|
|
@@ -50,7 +50,11 @@
|
|
50
50
|
|
51
51
|
Rails.application.routes.draw do
|
52
52
|
|
53
|
+
root to: 'static_pages#home'
|
54
|
+
|
55
|
+
devise_for :users
|
56
|
+
|
53
|
-
resources :
|
57
|
+
resources :reviews, only: [:index, :new, :create, :show]
|
54
58
|
|
55
59
|
resources :likes, only: [:create, :destroy]
|
56
60
|
|
@@ -60,7 +64,23 @@
|
|
60
64
|
|
61
65
|
```haml
|
62
66
|
|
67
|
+
-# index.html.haml
|
68
|
+
|
69
|
+
%h1 Reviews#index
|
70
|
+
|
71
|
+
- @reviews.each do |review|
|
72
|
+
|
73
|
+
.Cover
|
74
|
+
|
75
|
+
= link_to review_path(review) do
|
76
|
+
|
77
|
+
= image_tag "#{review.image}"
|
78
|
+
|
63
|
-
= link_to('いいね',
|
79
|
+
= link_to('いいね', reviews_path, method: :post)
|
80
|
+
|
81
|
+
= link_to('review', new_review_path)
|
82
|
+
|
83
|
+
= link_to('logout', destroy_user_session_path, method: :delete)
|
64
84
|
|
65
85
|
```
|
66
86
|
|