2014-10-27 23 views
0

我有創建一個新的Contract對象並在訂閱請求被批准時保存的功能。它在訂閱更新操作中被調用,並被提取到它自己的類中,而不是坐在模型或控制器中。記錄沒有保存在Heroku上,但在開發

在Heroku上,它在日誌中顯示500,但在該問題上沒有提供任何消息。其他代碼行繼續運行。

的代碼全部塊:

#Check to see the status of the subscription and that all of the checks have been completed 
     if @subscription.Approved == "In Review" or @subscription.Approved == "Pending" && @subscription.CompanyNameCheck == "Approved" && @subscription.CompanyAddressCheck == "Approved" && @subscription.CompanyVATCheck == "Approved" && @subscription.CompanyKVKNumberCheck == "Approved" && @subscription.KVKCheck == "Approved" && @subscription.IDCheck == "Approved" 
      #If everything is approved, then set the Subscription to approved and set the date 
      @subscription.Approved = "Approved" 
      @subscription.AcceptDate = Date.current 
      @subscription.save! 
      # Create a contract for the subscription 
      @company = Company.find(@subscription.company_id) 
      @contract = Contract.new(:company_id => @company.id, :subscription_type => @subscription.product.name, :company_type => @company.legal_entity, :subscription_id => @subscription.id, :CompanyName => @company.name) 
      @contract.save! 
      EventMailer.subscription_contract(@subscription, @contract).deliver 
     end 

行不執行:

 @company = Company.find(@subscription.company_id) 
     @contract = Contract.new(:company_id => @company.id, :subscription_type =>  @subscription.product.name, :company_type => @company.legal_entity, :subscription_id => @subscription.id, :CompanyName => @company.name) 
     @contract.save! 
     EventMailer.subscription_contract(@subscription, @contract).deliver 

Heroku的日誌:

2014-10-27T08:31:27.296463+00:00 heroku[router]: at=info method=GET path="/subscriptions/8/edit" host=tso.herokuapp.com request_id=a7ba490f-31fd-49ef-b282-3d65e978cab6 fwd="213.127.222.82" dyno=web.1 connect=1ms service=530ms status=200 bytes=10399 
    2014-10-27T08:31:38.053338+00:00 heroku[router]: at=info method=POST path="/subscriptions/8" host=tso.herokuapp.com request_id=2f51d682-8d10-4709-9390-b1eb6d724144 fwd="213.127.222.82" dyno=web.1 connect=1ms service=233ms status=500 bytes=1543 

回答

0

您需要將gem'rails_12factor'添加到您的Gemfile.Use此鏈接heroku setup

+0

我已經添加了rails_12factor gem,並且看到這個問題似乎是在創建合同時出現的2014-10-27T10:31:54.618554 + 00:00 app [web.1]:(2.4ms)BEGIN 2014 -10-27T10:31:54.623263 + 00:00 app [web.1]:(2.0ms)SELECT MAX(「contracts」。「id」)AS max_id FROM「contracts」 2014-10-27T10:31:54.623268 +00:00 app [web.1]:(2.0ms)SELECT MAX(「contracts」。「id」)AS max_id FROM「contracts」 2014-10-27T10:31:54.625577 + 00:00 app [web。 1]:(2.1ms)ROLLBACK 2014-10-27T10:31:54.625583 + 00:00 app [web.1]:(2.1ms)ROLLBACK '不清楚SELECT MAX失敗的原因 – user3252764 2014-10-27 11:38:24

+0

請粘貼您的代碼用於模型和控制器,以便糾正問題 – 2014-10-27 12:18:30

+0

找到了解決方案 - 這是模型中爲合同設置ID值的問題。你對模型的請求給了我更詳細的看模型的線索,它唯一可能的代碼是before_create回調函數,它將id設置爲從1000開始,而不是1.'self.id = [1000, self.class.maximum(:id)+1] .max if self.id.nil?'remove the code fixed the issue – user3252764 2014-10-27 13:11:30

0

您可以嘗試使用Logentries嘗試擴展的錯誤信息,或嘗試增加rails_12factor寶石

+0

好的。讓我們嘗試在heroku Rails控制檯中創建'@ contract'對象。請在這裏發佈一個系統答案。 – 2014-10-27 12:26:42

相關問題