Can’t use “type” as a database column name in Ruby on Rails

I was writing some Ruby on Rails code the other day, and one of my column, which I had named “type”, was not saving.

After some googling, apparently you can’t name your database column “type”. The word “type” is part of the magic field names, so it is reserved.

I thought this is kind of strange, and I also thought that scaffold should know this and drop some sort of error if you ever try to use these. This would really help newbies like myself, because this kind of error can take all night to diagnose.

  • Jen

    You can access the attribute by using

    model_name.attributes[‘type’]

    instead of

    model_name.type

    Hope it helps!