Error
The 500 server error https://kb.mediatemple.net/questions/1903/Why+am+I+getting+a+500+Internal+Server+Error+message?基本上是您的服务器出现内部问题(并且无法呈现您的请求)的所有时间的掩护
Rails 的错误处理将所有错误路由到您的/public
名为的目录422.html
, 404.html
and 500.html
-- 代表最常见的错误
您看到 500 错误的原因可能是应用程序内的任何内容。这是我要解决的问题:
环境
您在生产中遇到错误,这意味着环境的差异将导致问题
我首先会看看发生了什么变化。通常,是数据库或某些环境设置(不同的数据库提供程序等)导致了问题
DB
最常见的 500 错误是由开发和生产环境之间的数据库不一致引起的。我不了解 mongoid,但对于 MYSQL / PGSQL 之类的问题将与不在生产中迁移有关:
heroku run rake db:migrate
通常修复生产中的大多数数据库问题
异常通知
有一种非常好的宝石叫做异常通知 https://github.com/rails/exception_notification(摘自 Rails 核心),一个通过电子邮件发送错误通知的中间件:
#config/environments/production.rb
config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "Subject",
:sender_address => %{"notifier" <[email protected] /cdn-cgi/l/email-protection>},
:exception_recipients => %w{[email protected] /cdn-cgi/l/email-protection}
}
您需要获得SendGrid 插件 https://addons.heroku.com/sendgrid在 Heroku 中并将其添加到您的production.rb
:
#config/environments/production.rb
config.action_mailer.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}