【发布时间】: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