Home > Rails Reference, Ruby on Rails > Reserved words in Rails

Reserved words in Rails

Oh the agony… I just spent half a day agonising over a new model that I created, and didn’t work when I was doing a find for a record. Just because one of the column name is a named after a reserved word! The error was an obscure:

SyntaxError: compile error
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1359: syntax error, unexpected tINTEGER
Object::1

So I dedicate this blog entry to the listing of reserved words in Rails. If anyone else has come across any other reserved words that gave you hell, please comment!

Reserved words for Rails’ ActiveRecord
  • type
  • integer
  • string
  • text
  • file
  • number
Reserved words for Rails’ ActiveController
  • template ( Someone mentioned this on the Internet. I didn’t test this out )

Updates:

Some people have pointed me to these links.  They are more comprehensive!

  1. Remco
    June 16, 2007 at 5:25 pm

    Got the same mysterious error due to a column named ‘type’. Quite a common name for a column I would think. Anyway, thanks for posting this.

  2. JJ
    July 17, 2007 at 6:27 pm

    Unable to save a collection using a model with the name ‘Attribute’ when using the following model relationship

    Class Person < ActiveRecord::Base
    has_many :attributes
    end

    Doing this eventually fixed the problem:

    Class Person “Attribute”
    end

  3. JJ
    July 17, 2007 at 6:29 pm

    Not sure what happened above, the working fix should look like:

    Class Person “Attribute”
    end

  4. April 9, 2008 at 6:07 pm

    Strange errors like these for columns named “notify”

    FYI

  5. July 2, 2008 at 6:04 am

    Looks like the statement,

    has_many :tasks

    in your model will also reveal a reserved word…
    FYI

  6. May 13, 2009 at 11:33 pm

    Another one : “class”

    It’s OK to generate a migration with a class attribute and apply the migration, but in the console, I can’t create an entry.

  7. January 7, 2010 at 11:43 pm

    Another one: “send”. It is a reserved word because it is used in the Kernel (Kernel.send). It can not be used as a function name, otherwise we would override the Kernel Method. If you need it to describe some kind of message process, use a different word, for example “transmit”.

  8. Mike B
    October 30, 2010 at 12:33 am

    What’s stupid is that this is a problem for over 4 years! God forbid you might want to have a ‘type’ column in one of your tables.

  9. nathan kirk
    December 29, 2010 at 3:38 am

    this produces an error when used in a model:
    scope :parent, joins(:roles_users).where(‘roles.role = ?’, ‘Parent’)
    this does not:
    scope :parentx, joins(:roles_users).where(‘roles.role = ?’, ‘Parent’)

    I can’t find anywhere that “parent” is a reserved word–but i can easily imagine that it is.

  10. July 10, 2011 at 4:51 pm

    I’m finding this give me an error when using the model

    scope :parents, where(:kind => ‘parent’)

  11. Nick
    October 13, 2014 at 12:26 am

    I had a ‘type’ attribute in one of my models. I got errors when trying to seed my database.

  1. August 23, 2011 at 10:04 am
  2. September 25, 2012 at 11:59 pm
  3. November 17, 2013 at 3:42 pm
  4. December 12, 2015 at 8:26 am

Leave a reply to John W. Mount Cancel reply