Rails: Turn off error display
Try this:
run a server in production
$ rails s -e production
remove ActionDispatch::DebugExceptions middleware
config.middleware.delete(ActionDispatch::DebugExceptions)
set
config.consider_all_requests_local = false
in your environment config
How to turn off the red/grey error help page tool in rails development environment?
Try to the following
# config/environments/development.rb
config.consider_all_requests_local = false
By default, this value is true
because of the need to debug
code on development environment that's why, if you change value with false
then will show the error page which is designed default.
If you need to generate and design custom then the follow this tutorial.
Hope to help
Rails: hide errors errors in production environment
Make sure the following setting is set to false in your config/environment/production.rb
file:
config.consider_all_requests_local = false
How to enable error reporting when running a rails app in production mode?
If you add this to your config/environments/production.rb
:
config.consider_all_requests_local = true
You will see the same errors as in development, but it will also disable the caching for the production app etc.
I would rather suggest you look into /log/production.log
. The same errors are posted there as are normally shown on screen.
Disable stack trace display in Rails console
The important thing is that rails console use irb, and has access to the range of irb config options
$ rails c
Loading development environment (Rails 4.2.0)
>> conf
=> conf.ap_name="irb"
conf.auto_indent_mode=false
conf.back_trace_limit=16
.
.
.
And there it is: conf.back_trace_limit. So:
conf.back_trace_limit = 0
will effectively disable the backtrace for the current session, and output will be nice and concise:
>> MyModel.gnu
NoMethodError: undefined method `gnu' for MyModel:Class
or
>> obj.do_defective_math
ZeroDivisionError: divided by 0
To make things a bit more convenient, a function can be defined in ~/.irbrc. Something like:
def toggle_trace
if conf.back_trace_limit > 0
conf.back_trace_limit = 0
else
conf.back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
end
end
which can be called a console session to disable or enable the back trace as needed
Disable all html exception rendering in rails
What you want is exceptions_app
.
Rails exceptions_app
is basically a configuration option for rails which defaults to the middleware PublicExceptions
in ActionDispatch
.
This is pretty much what exceptions_app defaults to if none provided:
PublicExceptions
This is the public_exceptions middleware that handles displaying the public 500.html and 400.html
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/public_exceptions.rb
Show Exceptions
This is part of the middleware that shows exceptions on development/production
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L26
Defaults
Here's what it defaults to when you initialize an application
https://github.com/rails/rails/blob/master/railties/lib/rails/application.rb#L391-L393
You can exchange it for an app or route it to your own rails apps like this:
config/application.rb
config.exceptions_app = self.routes
Then in your routes you would match routes like this
routes.rb
match "/500" => "errors#exception"
match "/404" => "errors#not_found"
So you would then have a ErrorsController that would have these actions and handle the response to them.
errors_controller.rb
class ErrorsController < ApiController
def exception
render json: {error: "Internal Error"}, status: 500
end
def not_found
render json: {error: "Not Found"}, status: 404
end
end
Rails - error in production mode
In config/environments/production.rb
temporally change
config.consider_all_requests_local = false
to
config.consider_all_requests_local = true
Related Topics
How to Extend Redcarpet to Support Auto Linking User Mentions
Setting Mime Type for .Ogv Files in Rails Development Environment
Ruby Mailer Is Coming Up with an Eoferror
Access Ruby Hash Using Dotted Path Key String
Rails: Wkhtmltopdf Runtimeerror (Location of Wkhtmltopdf Unknown)
Commonmarker Gem Cannot Be Installed (Needed for Jekyll) MACos
How to Get the Number of Elements Having Same Attribute in HTML in Watir
Yielding in an Anonymous Block
Why Is Throw and Catch Hardly Ever Used in Ruby
Why Is Uri.Escape() Marked as Obsolete and Where Is This Regexp::Unsafe Constant
How to Evaluate a Date Difference in Years, Months and Days (Ruby)
How to Perform Vector Addition in Ruby
How to Use Variables in a Yaml File
How to Increment/Decrement a Character in Ruby for All Possible Values
Rails 4.0.3 Generating Incorrect Asset Paths with Asset_Sync