Rails - Know your models
I’ve been trying to upgrade a Rails app that worked on 1.2.6 to 2.0.2 for what seems like ever know. Granted what I mean by “working on” is that I’d spend at most an hour or so trying to tracking down exactly what was causing the one same error that I was getting anywhere I tested
ActionView::TemplateError valid? is defined by ActiveRecord
My assumption the whole time had been that it had to be a plugin, gem, some patching, or something we had defined screwy in our models that was not compatible with Rails 2. Really, it had to be - that covers the whole freakin’ app, so it should have been easy to find, right? Not for me. Seriously, I got this error for the 1st time at least 2 months ago. Luckily moving to Rails 2 wasn’t really a priority
Anywho, today I finally tracked down the problem. We had a field named “valid” in our model. Rails 1.2.6 didn’t give a crap about that - at all, ever. Turns out I’d overlooked the ONE time the field is looked at ever in the code this whole time. Once it intrigued me today, I started poking around - once I looked at our migrations, I finally realized that that was exactly what was conflicting here.
A quick migration to rename the column, a change to the one place it’s used, and voila! the app is running in Rails 2.
That was bullshit.
