Skip to content

Commit 5dcce10

Browse files
committed
feat: adding error page to handle active record not found
1 parent d9157ba commit 5dcce10

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ class ApplicationController < ActionController::Base
55
allow_browser versions: :modern
66

77
rescue_from ActiveRecord::RecordNotFound do |exception|
8-
render html: { error: "Record not found" }, status: :not_found
8+
render "errors/not_found", status: :not_found
99
end
1010
end

app/views/errors/not_found.html.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="min-h-screen bg-gray-50 flex flex-col justify-center py-8 sm:px-6 lg:px-8">
2+
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
3+
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
4+
<div class="text-center">
5+
<h1 class="text-6xl font-bold text-gray-900 mb-4">404</h1>
6+
<h2 class="text-2xl font-semibold text-gray-700 mb-4">Page Not Found</h2>
7+
<p class="text-gray-600 mb-8">Sorry, we couldn’t find the page you’re looking for.</p>
8+
<%= link_to "Go back home", root_path, class: "inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
9+
</div>
10+
</div>
11+
</div>
12+
</div>

0 commit comments

Comments
 (0)