简体   繁体   English

如何在Heroku部署中发现并调试500个错误,该错误在开发模式下似乎可以正常工作?

[英]how to find and debug a 500 error in a heroku deployment that appears to work and works fine in developement mode?

I figure I'll post this here as it'll hopefully save someone else the hours of tracing through each commit to see what the problem is. 我想将其发布在这里,因为它有望节省其他人跟踪每次提交以查看问题所在的时间。 I hadn't pushed to heroku in a few weeks and when I did the app crashed with a 500 html message. 几周后我没有推送到heroku,当我这样做时,该应用程序崩溃并显示了500条html消息。 no more information than that and the logs had nothng helpful to say whatsoever. 没有比这更多的信息了,日志无济于事。 nothing seemed atypical and nothing was out of the ordinary. 似乎没有什么异常,没有什么异常。 what was the solution? 解决方案是什么?

An unimplemented method in a controller, I had added a method new into a controller I hadn't implemented, I had no template or code in the method and it caused a 500 error on every page in the app, if your heroku push fails check all your controllers for unimplemented methods: 控制器中未实现的方法,我向未实现的控制器中添加了新方法,该方法中没有模板或代码,如果您的heroku push失败检查,则会在应用程序的每个页面上导致500错误您所有未实现方法的控制器:

class ContactTablesController < ApplicationController
    before_action :signed_in_user

  # respond_to :html, :js

  # def new #I added this to implement it later, started doing something else
  # end     # and forgot about it, uncommenting these lines brings the entire heroku app
            # down resulting in 500 errors

  def create
    # pp params[:contact_table] + " create"
    @user = User.find(params[:contact_table][:contact_id])
    current_user.add_contact!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end

  def destroy
    # pp params[:contact_table] + " destroy"
    @user = ContactTable.find(params[:id]).contact
    @id = ContactTable.where('user_id is ? AND contact_id is ?', current_user.id, @user.id).first.id 
    current_user.remove_contact!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end
end

I realise a lot of people might know that this happens but I didn't and it took a while of going through the code to notice it. 我意识到很多人可能知道这种情况会发生,但是我没有意识到,花了一些时间才能通过代码来注意到它。 hope it can help someone else. 希望它可以帮助别人。

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

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