質問編集履歴

5

routes.rbの内容

2020/08/22 02:31

投稿

Takashi1019
Takashi1019

スコア4

test CHANGED
File without changes
test CHANGED
@@ -188,6 +188,48 @@
188
188
 
189
189
 
190
190
 
191
+ routes.rb
192
+
193
+ Rails.application.routes.draw do
194
+
195
+ get '/' =>"home#top"
196
+
197
+ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
198
+
199
+ get 'posts/new' =>"posts#new"
200
+
201
+ post 'posts/create' => "posts#create"
202
+
203
+ get 'posts/:prefecture' =>"posts#index"
204
+
205
+ get 'posts/:prefecture/:id' => "posts#show"
206
+
207
+
208
+
209
+
210
+
211
+ post 'users/create'=>"users#create"
212
+
213
+ post 'users/login' =>"users#login"
214
+
215
+ post 'users/logout' => "users#logout"
216
+
217
+ get 'users/:id' =>"users#show"
218
+
219
+
220
+
221
+ post 'likes/:prefecture/:post_id/create' =>"likes#create"
222
+
223
+ post 'likes/:prefecture/:post_id/destroy' =>"likes#destroy"
224
+
225
+ post 'likes/:prefecture/create_index' =>"likes#create_index"
226
+
227
+ post 'likes/:prefecture/destroy_index' =>"likes#destroy_index"
228
+
229
+ end
230
+
231
+
232
+
191
233
  ```
192
234
 
193
235
 

4

rails routesの結果挿入

2020/08/22 02:30

投稿

Takashi1019
Takashi1019

スコア4

test CHANGED
File without changes
test CHANGED
@@ -142,6 +142,52 @@
142
142
 
143
143
 
144
144
 
145
+ rails routesの結果
146
+
147
+ rails routes
148
+
149
+ Prefix Verb URI Pattern Controller#Action
150
+
151
+ GET / home#top
152
+
153
+ posts_new GET /posts/new(.:format) posts#new
154
+
155
+ posts_create POST /posts/create(.:format) posts#create
156
+
157
+ GET /posts/:prefecture(.:format) posts#index
158
+
159
+ GET /posts/:prefecture/:id(.:format) posts#show
160
+
161
+ users_create POST /users/create(.:format) users#create
162
+
163
+ users_login POST /users/login(.:format) users#login
164
+
165
+ users_logout POST /users/logout(.:format) users#logout
166
+
167
+ GET /users/:id(.:format) users#show
168
+
169
+ POST /likes/:prefecture/:post_id/create(.:format) likes#create
170
+
171
+ POST /likes/:prefecture/:post_id/destroy(.:format) likes#destroy
172
+
173
+ POST /likes/:prefecture/create_index(.:format) likes#create_index
174
+
175
+ POST /likes/:prefecture/destroy_index(.:format) likes#destroy_index
176
+
177
+ rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show
178
+
179
+ rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
180
+
181
+ rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
182
+
183
+ update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
184
+
185
+ rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
186
+
187
+
188
+
189
+
190
+
145
191
  ```
146
192
 
147
193
 

3

destroy_indexアクションの編集

2020/08/21 08:51

投稿

Takashi1019
Takashi1019

スコア4

test CHANGED
File without changes
test CHANGED
@@ -128,11 +128,13 @@
128
128
 
129
129
  @posts=Post.where(prefecture: params[:prefecture])
130
130
 
131
- @post=Post.find_by(prefecture: params[:prefecture])
131
+ @posts.each do |post|
132
132
 
133
- @like = Like.find_by(user_id: @current_user.id, post_id:params[:post_id])
133
+ @like = Like.find_by(user_id: @current_user.id, post_id: post.id)
134
134
 
135
- @like.destroy
135
+ @like.destroy
136
+
137
+ end
136
138
 
137
139
  redirect_to("/posts/#{@prefecture}")
138
140
 

2

destroyアクション内の記述

2020/08/19 07:31

投稿

Takashi1019
Takashi1019

スコア4

test CHANGED
File without changes
test CHANGED
@@ -128,13 +128,11 @@
128
128
 
129
129
  @posts=Post.where(prefecture: params[:prefecture])
130
130
 
131
- @posts.each.with_index(1) do |post,i|
131
+ @post=Post.find_by(prefecture: params[:prefecture])
132
132
 
133
- @like = Like.find_by(user_id: @current_user.id, post_id: i)
133
+ @like = Like.find_by(user_id: @current_user.id, post_id:params[:post_id])
134
134
 
135
- @like.destroy
135
+ @like.destroy
136
-
137
- end
138
136
 
139
137
  redirect_to("/posts/#{@prefecture}")
140
138
 

1

link_to内のURLの変更

2020/08/19 06:29

投稿

Takashi1019
Takashi1019

スコア4

test CHANGED
File without changes
test CHANGED
@@ -60,7 +60,7 @@
60
60
 
61
61
  <% if Like.find_by(user_id: @current_user.id, post_id: post.id) %>
62
62
 
63
- <%= link_to("/likes/#{@prefecture}/#{post.id}/destroy_index", {method: "post"}) do %>
63
+ <%= link_to("/likes/#{@prefecture}/destroy_index", {method: "post"}) do %>
64
64
 
65
65
  <span class="fa fa-heart like-btn-unlike"></span>
66
66
 
@@ -68,7 +68,7 @@
68
68
 
69
69
  <% else %>
70
70
 
71
- <%= link_to("/likes/#{@prefecture}/#{post.id}/create_index", {method: "post"}) do %>
71
+ <%= link_to("/likes/#{@prefecture}/create_index", {method: "post"}) do %>
72
72
 
73
73
  <span class="fa fa-heart like-btn"></span>
74
74