-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Any unmatched route render 404 file directly
We've had some errors reported by Render since spammy requests coming in (e.g. POSTing to non-existent routes) so as a last resort in the routes file, any unmatched routes, just render the default 404 error page directly to avoid raising any errors.
- Loading branch information
1 parent
a918895
commit d219361
Showing
3 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery with: :exception | ||
|
||
def route_not_found | ||
render file: Rails.public_path.join("404.html"), status: :not_found, layout: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "application_system_test_case" | ||
|
||
class RouteNotFoundTest < ApplicationSystemTestCase | ||
test "visiting non-existent route renders 404 page" do | ||
visit "/does-not-exist" | ||
|
||
assert_text "The page you were looking for doesn't exist." | ||
end | ||
end |