【问题标题】:heroku error - NoMethodError (undefined method `updated?'heroku 错误 - NoMethodError(未定义的方法“更新?”
【发布时间】:2012-01-13 06:11:03
【问题描述】:

我在 Heroku 上有一个 rails 3.1 应用程序,我在生产中不断收到 500 错误,我无法在开发中重新创建。

当我尝试在我的一个控制器中执行更新操作时,我得到 500。我从 heroku 日志中得到以下信息 -

2011-12-05T13:52:35+00:00 app[web.1]: Completed 500 Internal Server Error in 15ms
2011-12-05T13:52:35+00:00 app[web.1]: 
2011-12-05T13:52:35+00:00 app[web.1]: NoMethodError (undefined method `updated?' for #<ActiveRecord::Associations::HasOneAssociation:0x00000004058800>):
2011-12-05T13:52:35+00:00 app[web.1]:   app/controllers/cars_controller.rb:81:in `block in update'
2011-12-05T13:52:35+00:00 app[web.1]:   app/controllers/cars_controller.rb:80:in `update'

我的汽车控制器上的更新操作是 -

def update
    @car = Car.find_by_url_identifier(params[:id])
    respond_to do |format| #**line 80**
      if @car.update_attributes(params[:car]) #**line 81**
        CarMailer.gift_confirmation(@car).deliver
        format.html { redirect_to(thanks_path(@car.url_identifier)) }
      else
        format.html { render action: "edit" }
      end
    end
end 

正在发布的参数是 -

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"RTXCVvdsKQHc8CxHLeYS9WuztcrI1b4H8SHsdfsKWu+Iz4=",
 "car"=>{"name"=>"dgdfsdfsd",
 "email"=>"test@test.com",
 "recipient_attributes"=>{"name"=>"fdsfsd",
 "address1"=>"sdfsdfdsf",
 "address2"=>"dsfdsfsdf",
 "city"=>"sdfdsf",
 "postcode"=>"sdfds"},
 "gift_id"=>"2",
 "message"=>"fsdfsdfdsf",
 "terms"=>"1"},
 "commit"=>"submit",
 "id"=>"test5"}

我的汽车模型是这样的 -

class Car < ActiveRecord::Base
  validates :name, :presence =>true, :on => :update
  validates :url_identifier, :presence =>true, :on => :create
  has_one :recipient
  belongs_to :gift
  accepts_nested_attributes_for :recipient 
  accepts_nested_attributes_for :gift 
  def to_param
    self.url_identifier
  end

end

知道如何解决这个问题吗?除了查看 herokus 日志,我还能如何调试它?

奇怪的是,如果我执行“heroku 重启”,应用程序会运行一段时间

【问题讨论】:

  • 你能告诉我们你的cars_controller的实际相关代码吗? (最好告诉我们这是第 80/81 行)?
  • 我已经添加了相关部分
  • 嗯 - 没有什么立竿见影的。 params[:car] 传递了什么信息?也许这是嵌套模型中出乎意料的事情?您对自己的车型有什么联想?
  • 我已添加帖子信息和模型 - 感谢您查看此内容。
  • 我用谷歌搜索了错误消息。你有没有看过这个帖子:ruby-forum.com/topic/81719他们有类似的问题并发布了他们的解决方案/黑客。可能值得一试。

标签: ruby-on-rails ruby-on-rails-3 activerecord deployment heroku


【解决方案1】:

我在代码中看不到任何错误。由于它适用于您的开发机器,我猜它是别的东西。有些区别。您是否在 heroku 上运行了迁移?

在 heroku 上部署后,您必须在单独的步骤中运行迁移。我不确定这是否会产生这种错误。这里只是猜测。

【讨论】:

  • 我刚刚在 heroku 上设置了一个新应用程序并再次运行了所有迁移 - 我仍然遇到同样的错误。
  • 您有需要启动或索引的搜索服务器吗? ...虽然这可能会在索引页面上出错...
【解决方案2】:

我用谷歌搜索了错误消息。你有没有看过这个帖子:http://ruby-forum.com/topic/81719他们有类似的问题并发布了他们的解决方案/黑客。也许值得尝试一下。

【讨论】:

    【解决方案3】:

    看起来您正在尝试将方法 update 调用到 ActiveRecord::Associations 对象而不是(可能)Car 模型,这很奇怪,因为您会认为它会被获取并在模型上调用,如果这不是在 Arel 中找到的方法。

    您可以尝试使用开发环境中的生产环境设置进行调试,方法是查看 config/enviroments/production.rb 并将这些设置用于开发。

    您也可以尝试使用 heroku console 在 heroku 上重新创建问题

    【讨论】:

      猜你喜欢
      • 2018-10-18
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多