Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rambulanceを使って404/500/422ページを整備 #1702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

nacchan99
Copy link
Contributor

@nacchan99 nacchan99 commented Jun 10, 2025

Resolves #1407

🛠 対応内容

404, 500, 422のエラーページがそれぞれ適切に表示されるように設定しました。

🚨 エラーページの追加と表示確認

  • ErrorsController を新しく作成
  • 各エラーコード用のアクション追加
    • not_found → 404
    • internal_server_error → 500
    • unprocessable_entity → 422
  • app/views/errors/ に対応する .html.erb ビューを作成
  • 既存の not_found.html.erb をベースに、他の2つのビューも統一デザインで作成
  • config/application.rb に Rambulance の設定を追記
  • routes.rbmount Rambulance::Engine => "/" を追加

🖼️ 表示確認(スクリーンショット)

404
スクリーンショット 2025-06-10 15 52 30

500
スクリーンショット 2025-06-11 9 17 20

422
スクリーンショット 2025-06-11 9 34 38

@yasulab
Copy link
Member

yasulab commented Jun 10, 2025

@nacchan99 PR ありがとうございます!可能そうならテストも追加してもらえると助かります!(>人< )✨(View の文言は頻繁に更新されるので、文言を頻繁に更新してもその都度テストを修正する必要がないテストだと嬉しいです! 🙇 )

@yasulab
Copy link
Member

yasulab commented Jun 10, 2025

あと 500 の部分にも以下の文言を追加していただけると助かります...!! (≧∇≦)b✨ (Partial にしても良いかも?)

image

@nacchan99
Copy link
Contributor Author

@yasulab
コメントありがとうござます!
今日の作業時間内では終わらなかったので、また明日再開します🙌

@nacchan99
Copy link
Contributor Author

@rakuda-san-desu
お疲れ様です!
対応が完了したので、一度ご確認をお願いします🙌

まだRSpec周りは手探りで進めている部分が多く、特にテストの書き方には自信がないので、書き方や構成に違和感があればご指摘いただけると嬉しいです…!🙇‍♀️

お手隙の際によろしくお願いします🙌

@yasulab yasulab self-requested a review June 11, 2025 08:15
</div>
<script async="" await="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</section>
<%= render 'errors/footer_links_and_timeline' %>
Copy link
Member

@yasulab yasulab Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error 専用の Partial にしては個々に分割しすぎな印象なので (個々に分けるメリットより個々に分けたことよる煩雑さが上回って僕がメンテするとき辛いので)、 共通化できる箇所のみを1つの Partial にまとめる ようにしていただけると助かります!(>人< )✨

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます!

errors/headerfeedback_notice はインライン化し、 footer_links_and_timeline のみ partial として残しました。

対応コミット:

  • errors/header のインライン化 ➡︎ 9dac37e
  • errors/feedback_notice のインライン化 ➡︎ c0d871a

ご確認よろしくお願いします!

Copy link
Contributor

@rakuda-san-desu rakuda-san-desu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実装ありがとうございます!

いくつかコメントしましたが、動作は良さそうです🙆‍♀️

@@ -0,0 +1,15 @@
class ErrorsController < ApplicationController
layout 'application' # エラー画面にも通常のアプリと同じレイアウトを適用
Copy link
Contributor

@rakuda-san-desu rakuda-san-desu Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このコメントはカットして良さそうです👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます!
こちらのコミットで対応済みです🙌 4b52ff7

layout 'application' # エラー画面にも通常のアプリと同じレイアウトを適用

def not_found
render status: 404 # このアクションでは app/views/errors/not_found.html.erb が使用されます
Copy link
Contributor

@rakuda-san-desu rakuda-san-desu Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他所も同様ですが、
該当する行の上にコメントを書くと、他の部分と統一されて良さそうです🛠️

    # このアクションでは app/views/errors/not_found.html.erb が使用されます
    render status: 404 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

統一しました🛠
対応コミットはこちらです→ 7e4737c

with_exceptions_app do
get '/does_not_exist'
end
expect(response.status).to eq(404)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「子どものためのプログラミング道場」など、必ず表示されるテキストが存在するかも確認しておくと、さらに安心できそうです👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テストを追加しました🙌
092c3dd
よろしくお願いします!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ローカルでエラーページを表示させたい
3 participants