質問編集履歴

1

情報の追加

2018/02/13 12:22

投稿

ninpig04
ninpig04

score0

test CHANGED
File without changes
test CHANGED
@@ -33,205 +33,3 @@
33
33
  自分では解決できませんでした。。。
34
34
 
35
35
  よろしくお願いします。
36
-
37
-
38
-
39
- 以下の情報を追記してもらえますか。①config/routes.rb,②「いいね」を押したときのリクエスト(ログファイルもしくは rails server したターミナルから拾う),③「いいね」を押したときのアクションのメソッド,④posts#show アクションのメソッド,⑤posts#show アクションに対応するビューのテンプレートのパス
40
-
41
-
42
-
43
- ```ここに言語を入力
44
-
45
- Rails.application.routes.draw do
46
-
47
-
48
-
49
- post "likes/:post_id/create" => "likes#create"
50
-
51
- post "likes/:post_id/destroy" => "likes#destroy"
52
-
53
-
54
-
55
- get "posts/index" => "posts#index"
56
-
57
- get "posts/new" => "posts#new"
58
-
59
- get "posts/:id" => "posts#show"
60
-
61
- post "posts/create" => "posts#create"
62
-
63
-
64
-
65
-
66
-
67
- get 'comments/index'
68
-
69
- get 'comments/:id' => 'comments#show'
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
- root 'static_pages#home'
82
-
83
- get '/help', to: 'static_pages#help'
84
-
85
- get '/configuration', to: 'static_pages#configuration'
86
-
87
- get '/about', to: 'static_pages#about'
88
-
89
- get '/contact', to: 'static_pages#contact'
90
-
91
- get '/top', to: 'static_pages#top'
92
-
93
- get '/signup', to: 'users#new'
94
-
95
- get '/login', to: 'sessions#new'
96
-
97
- post '/login', to: 'sessions#create'
98
-
99
- delete '/logout', to: 'sessions#destroy'
100
-
101
-
102
-
103
- get '/:city/:banti', to: 'comments#index'
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
- resources :users do
112
-
113
- member do
114
-
115
- get :following, :followers
116
-
117
- end
118
-
119
- end
120
-
121
- resources :account_activations, only: [:edit]
122
-
123
- resources :password_resets, only: [:new, :create, :edit, :update]
124
-
125
- resources :microposts, only: [:create, :destroy]
126
-
127
- resources :relationships, only: [:create, :destroy]
128
-
129
- end
130
-
131
- ```
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
- いいねを押した時のアクション
140
-
141
- ```ここに言語を入力
142
-
143
- class LikesController < ApplicationController
144
-
145
-
146
-
147
- def index
148
-
149
- end
150
-
151
-
152
-
153
- def create
154
-
155
- @like = Like.new(user_id: @current_user.id, post_id: params[:post_id])
156
-
157
- @like.save
158
-
159
- redirect_to("/posts/#{params[:post_id]}")
160
-
161
- end
162
-
163
-
164
-
165
-
166
-
167
- def destroy
168
-
169
- @like = Like.find_by(user_id: @current_user.id, post_id: params[:post_id])
170
-
171
- @like.destroy
172
-
173
- redirect_to("/posts/#{params[:post_id]}")
174
-
175
- end
176
-
177
-
178
-
179
- end
180
-
181
-
182
-
183
- ```
184
-
185
- posts#showのメソッド(いいねのページはCommentsのshowです)
186
-
187
- ```ここに言語を入力
188
-
189
- def show
190
-
191
- @post = Post.find_by(id: params[:id])
192
-
193
- @likes_count = Like.where(post_id: @post.id).count
194
-
195
- end
196
-
197
- ```
198
-
199
-
200
-
201
- パスは
202
-
203
- app/views/posts/show.html.erbです
204
-
205
-
206
-
207
- ちなみに、comments#showのメソッドは
208
-
209
- ```ここに言語を入力
210
-
211
- class CommentsController < ApplicationController
212
-
213
-
214
-
215
-
216
-
217
- def show
218
-
219
- @comments = Comment.find_by(id: params[:id])
220
-
221
- @posts = Post.where(comment_id: @comment.id)
222
-
223
- @current_user = User.find_by(id: session[:user_id])
224
-
225
- @post = Post.find_by(id: params[:id])
226
-
227
- @likes_count = Like.where(post_id: @post.id).count
228
-
229
- end
230
-
231
- end
232
-
233
- ```
234
-
235
-
236
-
237
- です