0

I am using the exception_handler gem to make a custom 404 page. When I go to the 404 page on my site and it shows not found but how do I customize this page? I tried changing the routes, make errors_controller and not_found view.

application.rb

config.exceptions_app = self.routes

routes.rb

  get "/404", :to => "errors#not_found"
  get "/422", :to => "errors#unacceptable"
  get "/500", :to => "errors#internal_error"

errors_controller.rb

class ErrorsController < ApplicationController

  def not_found
    render :status => 404   end

  def unacceptable
    render :status => 422   end

  def internal_error
    render :status => 500   end

end

app/views/errors/not_found.html.erb

<label> TEST 404 Label </label>
jrocc
  • 1,274
  • 2
  • 18
  • 48

2 Answers2

1

It's very possible that you have configured those pages properly and that the code would work but just not for the environment that you're working in. In the directory config/environments you should have three files: development, test, production. When you're working in development it won't render those pages you've created as it's defaulting to Rails errors. You should check in config/environments/development.rb and see what you have config.consider_all_requests_local set to. You can change this to false, reset the router and be able to see the error pages, then swap it back to true when moving on to further development. Please note that the implementation you've used looks like an alternative to the exception_handler gem and would handle errors instead of that gem.

You can find more info here in Rails guides: http://guides.rubyonrails.org/configuring.html#rails-general-configuration

Stephen W
  • 244
  • 2
  • 7
1

I forgot to run rails g exception_handler:views this generated all the views in my project file now I can customize them to my liking.

jrocc
  • 1,274
  • 2
  • 18
  • 48
  • I wrote and maintain the gem - if you need any direct support, you're welcome to email rpeck@frontlineutilities.co.uk – Richard Peck Mar 18 '18 at 16:08