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
endImagine 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.
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