How To Add Custom 404 Not Found Pages With Rails

Posted By Weston Ganger

Here I present a couple way to add custom 404 Not Found pages to your Rails app.

This is particularily useful so that your not found pages get rendered with the applications layout and styles. Also helps add some minor security so that users cannot tell that it is a Rails app based on the default error page.

Common Code

### config/application.rb
config.exceptions_app = self.routes

### config/routes.rb
match '/404', to: 'application#render_404', via: :get

Article Topic:Software Development - Ruby / Rails

Date:February 15, 2022