1

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"=>"[email protected]",
 "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'

6
  • can you show us the actual relevant code from your cars_controller? (preferably indicating to us which is line 80/81)?
    – Taryn East
    Dec 5, 2011 at 14:09
  • I've added the relevant section
    – Finnnn
    Dec 5, 2011 at 14:15
  • Hmm - nothing immediately obvious. what information was being passed at the params[:car] ? perhaps it's something unexpected in a nested model? What associations do you have on your car model?
    – Taryn East
    Dec 5, 2011 at 14:19
  • I've added the post info and the model - thanks for looking at this.
    – Finnnn
    Dec 5, 2011 at 14:29
  • I googled the error message. Have you had a look at this thread: ruby-forum.com/topic/81719 They had a similar problem and have posted their solution/hack. Might be worth a try.
    – Taryn East
    Dec 5, 2011 at 16:03

3 Answers 3

2

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.

2
  • I've just set up a new app on heroku and ran all the migrations again - I'm still getting the same error.
    – Finnnn
    Dec 5, 2011 at 15:59
  • Do you have a search server you need to start or index? ... That would probably error on the index page though...
    – bennett_an
    Dec 5, 2011 at 17:44
1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.