File tree Expand file tree Collapse file tree 1 file changed +22
-12
lines changed Expand file tree Collapse file tree 1 file changed +22
-12
lines changed Original file line number Diff line number Diff line change 1
1
class ErrorsController < ApplicationController
2
- layout 'application'
2
+ before_action :set_error_message
3
3
4
- def not_found
5
- # このアクションでは app/views/errors/not_found.html.erb が使用されます
6
- render status : 404
4
+ def show
5
+ render :show , status : @status_code
7
6
end
8
7
9
- def internal_server_error
10
- # このアクションでは app/views/errors/internal_server_error.html.erb が使用されます
11
- render status : 500
12
- end
8
+ private
13
9
14
- def unprocessable_entity
15
- # このアクションでは app/views/errors/unprocessable_entity.html.erb が使用されます
16
- render status : 422
17
- end
10
+ def set_error_message
11
+ @status_code = params [ :status_code ] . to_i
12
+
13
+ case @status_code
14
+ when 404
15
+ @title = "ページが見つかりませんでした... 🥺💦"
16
+ @desc = "ページが削除された可能性があります 🤔💭"
17
+ when 422
18
+ @title = "リクエストが処理できませんでした… 😢"
19
+ @desc = "入力内容に誤りがあるか、リクエストが正しく送信されなかった可能性があります。"
20
+ when 500
21
+ @title = "予期しないエラーが発生しました 😵💫"
22
+ @desc = "申し訳ありません。サーバーで問題が発生しています。"
23
+ else
24
+ @title = "予期せぬエラーが発生しました…😵"
25
+ @desc = "しばらく経ってから再度お試しください。"
26
+ end
27
+ end
18
28
end
You can’t perform that action at this time.
0 commit comments