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!

About these ads
  1. Remco
    June 16, 2007 at 5:25 pm | #1

    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 | #2

    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 | #3

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

    Class Person “Attribute”
    end

  4. April 9, 2008 at 6:07 pm | #4

    Strange errors like these for columns named “notify”

    FYI

  5. July 2, 2008 at 6:04 am | #5

    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 | #6

    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 | #7

    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 | #8

    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 | #9

    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 | #10

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

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

  1. August 23, 2011 at 10:04 am | #1
  2. September 25, 2012 at 11:59 pm | #2
  3. November 17, 2013 at 3:42 pm | #3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: