Developing a rails app on localhost, whenever there is an error you can see the error in detail on the rails page that comes up. But, on Heroku, the only thing that appears when there is an error, is "We're sorry, but something went wrong." with no information. I've seen the logs, and that doesn't seem to help. Is there a way to replace that generic Heroku error page, with the detailed Rails error page?
This isn't a heroku-specific issue, but a production environment one. In any production setting, you can display full errors on by changing this line in your config/environments/production.rb
config.consider_all_requests_local = false
to
config.consider_all_requests_local = true
Note that a better alternative so it's not visible to users is to continue to display the production style error, and tail the log files instead using:
heroku logs --app <yourappname> --tail
This will run a stream of the log file so you don't miss anything rather than just the last 40 lines.
If you aren't seeing enough information, then in config/environments/production
add or change the log_level to debug
config.log_level = :info
Or you could reset the log level using an environment variable, so you can just remove it and restart rather than redeploying with:
heroku config:add LOG_LEVEL=DEBUG --app <yourappname>
This could get you going..
routes.rb
match "/404", :to => "exceptions#some_error"
match "/500", :to => "exceptions#some_error"
#add some more?
so then,
class ExceptionsController < ApplicationController
def some_error
@exception = env["action_dispatch.exception"]
@status_code = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
end
end
a view page finally, to display sort of exception, you will be fixing.
In your rails app, under config/environments/production.rb
, try changing
config.consider_all_requests_local = false
to
config.consider_all_requests_local = true
Note: You may want to set up a new environment and deploy that to Heroku when you want to see the normal rails error messages. Maybe something like staging
or testing
since you don't want users seeing these kinds of errors on a live site.
I feel your pain. Try running heroku run rails console
for a clearer error. Hope that helps
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.