简体   繁体   中英

Ruby on Rails error handling

In my production Ruby on Rails app, a 500 error page will show the source code of the controller where the error occurred. Obviously these errors should be handled in the first place, but I am dealing with a ton of legacy code.

Is there a way to create a custom error page that will not reveal my source code when an error is thrown?

In you development.rb general configuration of your app, there's a flag

config.consider_all_requests_local = true

which is true , by default, in development. If you set that to false (the default in production), you can see the error page that users will see in your production app. This page is in public/500.html and public/404.html if you want to customize those.

You can also search around for ways to have Rails use ERB to create a custom error page, there are lots of tutorials on that, but I haven't used any and thus can't recommend one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM