While porting an application from Rails 1.2.3 to Rails 2.1, I encountered the error message in the title of this post. This particularly application has roots in pre-Rails 1.2.3 days, and the process of porting mainly consisted of simple things like removing calls to end_form_tag, modifying the call to form_tag to use a block, and finding the appropriate url generating method for nested resources. It was going smoothly, though a bit tedious, up until this point.

After examining the call stack, I noticed only one line was a reference to the application code. Surely the error was there, right? I checked the referenced line in my application and found the following:

   1  if @event.update_attributes(params[:event])
   2    ...
   3  end

At this point, I got a little concerned. I knew there was nothing wrong with the call to update_attributes. Then I remembered that the Rails 1.2.3 version of the application made use of acts_as_tree which was later extracted into a plugin (which I had to install during the process of porting). So the next logical step was to peruse the source of the acts_as_tree plugin. I didn’t find any crazy monkey patching going on in the plugin, which was simultaneously comforting and troubling. After searching the tubes a bit, I stumbled across this post. I thought to myself, “Hey, I remember that post. I remember telling former_colleague about that post when I found it.” It also happens former_colleague was the original developer of the application. But it still didn’t dawn on me at that point, so I just decided to check every location where ActiveRecord was being monkey patched (thankfully, there were not many). The first place I checked slapped me in the face—it was one of the patches demonstrated in the above post.

I removed the offending code, and walked away feeling a little more seasoned. While I have been doing Ruby on and off for awhile, that was the first time I had to debug an issue involving monkey patching.