Why is my code in a loop?

Today, I wrote some code that looked a little bit like this:

class Model < ActiveRecord::Base

  ...

  def update
    RAILS_DEFAULT_LOGGER.info "Update Called"
    # Read some data from wherever
    # Set some properties on my object
    save!
  end
end

Imagine my surprise when my log output was a long stream of Update Called lines.

What happened here is that save is implemented as a call to update when the object already exists.

Inadvertently picking a method name that is the same as an important Rails method can be hard to track down. I already had my logging in there, so I wasn’t left wondering why the call never completed.

This entry was posted on Thu, 25 Jan 2007 04:09:42 GMT . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.
Tags


Trackbacks

Use the following link to trackback from your own site:
http://blog.craz8.com/trackbacks?article_id=why-is-my-code-in-a-loop&day=24&month=01&year=2007

Comments

Leave a response

Leave a comment