heroku error - NoMethodError (undefined method `up

2019-08-03 20:12发布

I've a rails 3.1 app on Heroku, I keep getting an 500 error in production which I can't recreate in dev.

When I try to perform an update action in one of my controllers I get a 500. I get the following from heroku logs -

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'

The update action on my cars controller is -

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 

The parameters being posted are -

{"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"}

My car model looks like this -

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

Any idea how I can fix this? Apart from looking at herokus logs, how else can I debug this?

Oddly the app work for a while if I do a 'heroku restart'

3条回答
劳资没心,怎么记你
2楼-- · 2019-08-03 20:42

I googled the error message. Have you had a look at this thread: http://ruby-forum.com/topic/81719 They had a similar problem and have posted their solution/hack. Might be worth a try.

查看更多
Fickle 薄情
3楼-- · 2019-08-03 20:44

It looks like you are trying to call the method update to an ActiveRecord::Associations object instead of (probably) the Car model, which is strange because you would think it would be fetched and called on the model if it isn't a method found in Arel.

You could try to debug this by using the production environment settings in your development environment by looking in config/enviroments/production.rb and using those settings for development.

You could also try and recreate the problem on heroku using heroku console

查看更多
一夜七次
4楼-- · 2019-08-03 20:55

I can't see anything wrong in the code. Since it works on your development machine, I am guessing it is something else. Some difference. Did you run your migrations on heroku?

After deploying on heroku, you have to run your migrations in a separate step. I am not sure if that would give this kind of error. Just guessing here.

查看更多
登录 后发表回答