Rails 3.1 Model Property Name Gotcha

Last updated on 28 Oct 2011

If you’re trying to instantiate a Rails model and you keep getting nil back instead of an instance of that model, chances are you have done something dumb like try to create a property on that model called “class”, or something equally ill-advised.

I haven’t tested this for all Ruby keywords, but chances are good that if the build in Object class has an instance property by the same name as one of your model properties, you’re going to run into trouble.

It’s obvious when you’re not dealing with the consequences, but when you’re sitting there in a console and your .new instantiation is returning nil, this get pretty confusing.