質問編集履歴

2

rails routesコマンド実行結果を追記いたしました。

2021/05/13 12:52

投稿

gaugau_2
gaugau_2

スコア0

test CHANGED
File without changes
test CHANGED
@@ -284,6 +284,54 @@
284
284
 
285
285
  ```
286
286
 
287
+ 以下、rails routesコマンドを実行した結果になります。
288
+
289
+ ```
290
+
291
+ ec2-user:~/environment/sample_app (account-activation) $ rails routes
292
+
293
+ Prefix Verb URI Pattern Controller#Action
294
+
295
+ sessions_new GET /sessions/new(.:format) sessions#new
296
+
297
+ users_new GET /users/new(.:format) users#new
298
+
299
+ root GET / static_pages#home
300
+
301
+ help GET /help(.:format) static_pages#help
302
+
303
+ about GET /about(.:format) static_pages#about
304
+
305
+ contact GET /contact(.:format) static_pages#contact
306
+
307
+ signup GET /signup(.:format) users#new
308
+
309
+ login GET /login(.:format) sessions#new
310
+
311
+ POST /login(.:format) sessions#create
312
+
313
+ logout DELETE /logout(.:format) sessions#destroy
314
+
315
+ users GET /users(.:format) users#index
316
+
317
+ POST /users(.:format) users#create
318
+
319
+ new_user GET /users/new(.:format) users#new
320
+
321
+ edit_user GET /users/:id/edit(.:format) users#edit
322
+
323
+ user GET /users/:id(.:format) users#show
324
+
325
+ PATCH /users/:id(.:format) users#update
326
+
327
+ PUT /users/:id(.:format) users#update
328
+
329
+ DELETE /users/:id(.:format) users#destroy
330
+
331
+ edit_account_activation GET /account_activations/:id/edit(.:format) account_activations#edit
332
+
333
+ ```
334
+
287
335
 
288
336
 
289
337
  ほかにもエラーが発生しているのですが、抜粋して質問させていただきました。

1

users_controllersのコードを追加しました。

2021/05/13 12:52

投稿

gaugau_2
gaugau_2

スコア0

test CHANGED
File without changes
test CHANGED
@@ -122,6 +122,168 @@
122
122
 
123
123
  ```
124
124
 
125
+ 以下、users_controllersのコードです。
126
+
127
+ destroyの項目があるのにエラーが出てしまっております。
128
+
129
+ ```
130
+
131
+ class UsersController < ApplicationController
132
+
133
+ before_action :logged_in_user, only: [:index, :edit, :update, :destroy]
134
+
135
+ before_action :correct_user, only: [:edit, :update]
136
+
137
+ before_action :admin_user, only: :destroy
138
+
139
+
140
+
141
+ def index
142
+
143
+ @users = User.paginate(page: params[:page])
144
+
145
+ end
146
+
147
+
148
+
149
+ def show
150
+
151
+ @user = User.find(params[:id])
152
+
153
+ end
154
+
155
+
156
+
157
+ def new
158
+
159
+ @user = User.new
160
+
161
+ end
162
+
163
+
164
+
165
+ def create
166
+
167
+ @user = User.new(user_params)
168
+
169
+ if @user.save
170
+
171
+ log_in @user
172
+
173
+ flash[:success] = "Welcome to the Sample App!"
174
+
175
+ redirect_to @user
176
+
177
+ else
178
+
179
+ render 'new'
180
+
181
+ end
182
+
183
+ end
184
+
185
+
186
+
187
+ def edit
188
+
189
+ @user = User.find(params[:id])
190
+
191
+ end
192
+
193
+
194
+
195
+ def update
196
+
197
+ @user = User.find(params[:id])
198
+
199
+ if @user.update_attributes(user_params)
200
+
201
+ flash[:success] = "Profile updated"
202
+
203
+ redirect_to @user
204
+
205
+ else
206
+
207
+ render 'edit'
208
+
209
+ end
210
+
211
+
212
+
213
+ def destroy
214
+
215
+ User.find(params[:id]).destroy
216
+
217
+ flash[:success] = "User deleted"
218
+
219
+ redirect_to users_url
220
+
221
+ end
222
+
223
+
224
+
225
+ private
226
+
227
+
228
+
229
+ def user_params
230
+
231
+ params.require(:user).permit(:name, :email, :password,
232
+
233
+ :password_confirmation)
234
+
235
+ end
236
+
237
+
238
+
239
+ # beforeアクション
240
+
241
+
242
+
243
+ # ログイン済みユーザーかどうか確認
244
+
245
+ def logged_in_user
246
+
247
+ unless logged_in?
248
+
249
+ store_location
250
+
251
+ flash[:danger] = "Please log in."
252
+
253
+ redirect_to login_url
254
+
255
+ end
256
+
257
+ end
258
+
259
+
260
+
261
+ # 正しいユーザーかどうか確認
262
+
263
+ def correct_user
264
+
265
+ @user = User.find(params[:id])
266
+
267
+ redirect_to(root_url) unless current_user?(@user)
268
+
269
+ end
270
+
271
+
272
+
273
+ # 管理者かどうか確認
274
+
275
+ def admin_user
276
+
277
+ redirect_to(root_url) unless current_user.admin?
278
+
279
+ end
280
+
281
+ end
282
+
283
+ end
284
+
285
+ ```
286
+
125
287
 
126
288
 
127
289
  ほかにもエラーが発生しているのですが、抜粋して質問させていただきました。