简体   繁体   English

显示Rails错误页面而不是模糊的Heroku错误页面的方法

[英]Way to display Rails error page instead of vague Heroku error pages

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. 在本地主机上开发Rails应用程序,每当出现错误时,您都可以在出现的Rails页面上详细查看该错误。 But, on Heroku, the only thing that appears when there is an error, is "We're sorry, but something went wrong." 但是,在Heroku上,出现错误时唯一出现的是“很抱歉,但出了点问题”。 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? 有没有办法用详细的Rails错误页面替换该通用Heroku错误页面?

This isn't a heroku-specific issue, but a production environment one. 这不是特定于heroku的问题,而是生产环境中的问题。 In any production setting, you can display full errors on by changing this line in your config/environments/production.rb 在任何生产设置中,可以通过在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. 这将运行日志文件流,因此您不会错过任何事情,而不会错过最后40行。

If you aren't seeing enough information, then in config/environments/production add or change the log_level to debug 如果您没有看到足够的信息,请在config/environments/production添加或更改log_level以进行调试

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 的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 在您的Rails应用中的config/environments/production.rb ,尝试更改

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. 注意:当您想查看正常的Rails错误消息时,您可能需要设置一个新环境并将其部署到Heroku。 Maybe something like staging or testing since you don't want users seeing these kinds of errors on a live site. 也许是stagingtesting类的事情,因为您不希望用户在实时站点上看到此类错误。

I feel your pain. 我感到你很痛苦。 Try running heroku run rails console for a clearer error. 尝试运行heroku run rails console以获得更清晰的错误。 Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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