質問編集履歴

2

改善するうちに、コード、エラー内容が変わったため

2020/09/10 21:12

投稿

renren
renren

スコア48

test CHANGED
@@ -1 +1 @@
1
- Unknown action解決できない
1
+ link_to の遷移先上手くいかない
test CHANGED
@@ -1,8 +1,6 @@
1
1
  現在、railsにてdeviseを用いてinstagram風のアプリを作成しているのですが、
2
2
 
3
- パスワード変更ページに遷移するリンクを押すと下記エラが発生しました
3
+ パスワード変更ページに遷移するリンクを押すとなぜか、サインインペジにリダイレクトされてしまいます
4
-
5
- アクションは書いているのですが、エラーの原因が解決できず困っております。
6
4
 
7
5
 
8
6
 
@@ -16,19 +14,27 @@
16
14
 
17
15
 
18
16
 
19
-
20
-
21
- エラーメッセージ
22
-
23
- ```
24
-
25
- Unknown action
26
-
27
- Could not find devise mapping for path "/users/password/edit.101". This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router. If so, you can explicitly tell Devise which mapping to use: @request.env["devise.mapping"] = Devise.mappings[:user]
28
-
29
- ```
30
-
31
-
17
+ rails routes
18
+
19
+ ```
20
+
21
+ new_user_password GET /users/password/new(.:format) users/passwords#new
22
+
23
+ edit_user_password GET /users/password/edit(.:format) users/passwords#edit
24
+
25
+ user_password PATCH /users/password(.:format) users/passwords#update
26
+
27
+ PUT /users/password(.:format) users/passwords#update
28
+
29
+ POST /users/password(.:format) users/passwords#create
30
+
31
+ cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
32
+
33
+ new_user_registration GET /users/sign_up(.:format) users/registrations#new
34
+
35
+ edit_user_registration GET /users/edit(.:format) users/registrations#edit
36
+
37
+ ```
32
38
 
33
39
 
34
40
 
@@ -162,15 +168,29 @@
162
168
 
163
169
  root 'pages#top'
164
170
 
165
- get 'users/password/edit', to:'devise/passwords#edit'
166
-
167
- devise_for :users, controllers: { registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks' }
171
+ devise_for :users, controllers: { registrations: 'users/registrations', omniauth_callbacks: 'users/omniauth_callbacks',
172
+
168
-
173
+ passwords: 'users/passwords'}
174
+
175
+ resources :users do
176
+
177
+ member do
178
+
179
+ get :following, :followers
180
+
181
+ end
182
+
183
+ end
184
+
169
- resources :users, :only => [:show, :edit, :update, :index]
185
+ resources :users, only: [:show, :index, :destroy]
186
+
170
-
187
+ resources :microposts, only: [:create, :destroy]
188
+
189
+ resources :relationships, only: [:create, :destroy]
190
+
171
- get '/notification', to:'pages#notification'
191
+ get '/notification', to:'pages#notification'
172
-
192
+
173
- get '/post', to:'pages#post'
193
+ get '/post', to:'pages#post'
174
194
 
175
195
  end
176
196
 
@@ -182,72 +202,34 @@
182
202
 
183
203
  ```
184
204
 
185
- # frozen_string_literal: true
186
-
187
-
188
-
189
205
  class Users::PasswordsController < Devise::PasswordsController
190
206
 
191
- # GET /resource/password/new
207
+
192
-
208
+
193
- def new
209
+ def edit
210
+
211
+ binding.pry
194
212
 
195
213
  super
196
214
 
215
+ binding.pry
216
+
217
+ redirect_to edit_user_password_path(@user)
218
+
219
+ #redirect_to edit_user_password_path
220
+
221
+ binding.pry
222
+
197
- end
223
+ end
198
-
199
-
200
-
201
- # POST /resource/password
224
+
202
-
225
+
226
+
203
- def create
227
+ def update
204
228
 
205
229
  super
206
230
 
207
231
  end
208
232
 
209
-
210
-
211
- # GET /resource/password/edit?reset_password_token=abcdef
212
-
213
- def edit
214
-
215
- super
216
-
217
- end
218
-
219
-
220
-
221
- # PUT /resource/password
222
-
223
- def update
224
-
225
- super
226
-
227
- end
228
-
229
-
230
-
231
- protected
232
-
233
-
234
-
235
- def after_resetting_password_path_for(resource)
236
-
237
- super(resource)
238
-
239
- end
240
-
241
-
242
-
243
- The path used after sending reset password instructions
244
-
245
- def after_sending_reset_password_instructions_path_for(resource_name)
246
-
247
- super(resource_name)
248
-
249
- end
250
-
251
233
  end
252
234
 
253
235
  ```
@@ -262,11 +244,13 @@
262
244
 
263
245
 
264
246
 
265
- before_action :authenticate_user!, only: [:show, :edit, :update]
247
+ before_action :authenticate_user!, only: [:show, :destroy, :index, :following, :followers]
266
-
248
+
267
- before_action :set_user, only: [:show, :edit, :update]
249
+ before_action :set_user, only: [:show]
268
-
250
+
269
- before_action :admin_user, only: :destroy
251
+ before_action :admin_user, only: [:destroy]
252
+
253
+ before_action :current_user, only: [:index]
270
254
 
271
255
 
272
256
 
@@ -282,39 +266,9 @@
282
266
 
283
267
  @user = current_user
284
268
 
285
- end
286
-
287
-
288
-
289
- def edit
290
-
291
- # 編集するユーザーが本人じゃない場合はユーザーページにリダイレクトする
292
-
293
269
  #binding.pry
294
270
 
295
- unless @user == current_user
296
-
297
- redirect_to user_path(@user)
298
-
299
- end
300
-
301
- end
302
-
303
-
304
-
305
- def update
306
-
307
- binding.pry
308
-
309
- if @user.update(user_params)
310
-
311
- redirect_to user_path(current_user)
312
-
313
- else
314
-
315
- redirect_to edit_user_registration_path(current_user)
271
+ @microposts = @user.microposts.paginate(page: params[:page])
316
-
317
- end
318
272
 
319
273
  end
320
274
 
@@ -332,6 +286,24 @@
332
286
 
333
287
 
334
288
 
289
+ #def update
290
+
291
+ #binding.pry
292
+
293
+ #if @user.update(user_params)
294
+
295
+ #redirect_to user_path(current_user)
296
+
297
+ #else
298
+
299
+ #redirect_to edit_user_registration_path(current_user)
300
+
301
+ #end
302
+
303
+ #end
304
+
305
+
306
+
335
307
  private
336
308
 
337
309
 
@@ -350,6 +322,28 @@
350
322
 
351
323
  end
352
324
 
325
+
326
+
327
+ # 管理者かどうか確認
328
+
329
+ def admin_user
330
+
331
+ redirect_to(root_url) unless current_user.admin?
332
+
333
+ end
334
+
335
+
336
+
337
+ # 正しいユーザーかどうか確認
338
+
339
+ def correct_user
340
+
341
+ @user = User.find(params[:id])
342
+
343
+ redirect_to(root_url) unless current_user?(@user)
344
+
345
+ end
346
+
353
347
  end
354
348
 
355
349
  ```

1

各コードのファイル名が反映されていなかったので修正しました。

2020/09/10 21:12

投稿

renren
renren

スコア48

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,11 @@
16
16
 
17
17
 
18
18
 
19
+
20
+
19
- ```エラーメッセージ
21
+ エラーメッセージ
22
+
23
+ ```
20
24
 
21
25
  Unknown action
22
26
 
@@ -26,7 +30,11 @@
26
30
 
27
31
 
28
32
 
33
+
34
+
29
- ```app/views/devise/registrations/edit.htmo.erb
35
+ app/views/devise/registrations/edit.htmo.erb
36
+
37
+ ```
30
38
 
31
39
  <% provide(:title, @user.username) %>
32
40
 
@@ -88,7 +96,9 @@
88
96
 
89
97
 
90
98
 
91
- ```app/views/devise/passwords/edit.htmo.erb
99
+ app/views/devise/passwords/edit.htmo.erb
100
+
101
+ ```
92
102
 
93
103
  <h2>Change your password</h2>
94
104
 
@@ -144,7 +154,9 @@
144
154
 
145
155
 
146
156
 
147
- ```config/routes.rb
157
+ config/routes.rb
158
+
159
+ ```
148
160
 
149
161
  Rails.application.routes.draw do
150
162
 
@@ -166,7 +178,9 @@
166
178
 
167
179
 
168
180
 
169
- ``` app/controllers/users/passwords_controller.rb
181
+ app/controllers/users/passwords_controller.rb
182
+
183
+ ```
170
184
 
171
185
  # frozen_string_literal: true
172
186
 
@@ -240,7 +254,9 @@
240
254
 
241
255
 
242
256
 
243
- ``` app/controllers/users_controller.rb
257
+ app/controllers/users_controller.rb
258
+
259
+ ```
244
260
 
245
261
  class UsersController < ApplicationController
246
262