Piku’s Blog

January 19, 2008

ActiveRecord ‘type’ error

Filed under: Programming, Ruby on Rails — Tags: , , — Mihai @ 10:03 pm

While playing with Rails and ActiveRecord with has_many :through associations found an interesting error

> Account.find :all
SyntaxError: compile error
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1748: syntax error, unexpected tINTEGER

It took me some time to figure this out so I thought it might be useful to post it here, maybe someone has the same problem.

The error is because of the ‘type’ attribute of Account model, in Rails it is reserved for single table inheritance. To fix this just do not use an attribute called ‘type’, rename it to something else.

Advertisement

5 Comments »

  1. Thank you, you saved my life!!

    Comment by Anand Chhatpar — January 26, 2008 @ 9:41 pm

  2. Thank you, for saving my time!

    Comment by Egg — February 23, 2008 @ 5:26 pm

  3. That’s a good an simple answer, thanks.

    Comment by xvaib — April 11, 2008 @ 5:40 pm

  4. Thanks! Helped.

    Comment by Matthew J Mucklo — May 27, 2008 @ 10:41 pm

  5. Sweet! This is the exact problem I was having. Couldn’t figure it out for the life of me. It would be nice if it gave an error message like “Don’t use ‘type’, it is reserved”. I too was using a has_many :through, but removing it didn’t fix it, so I assume that it was just a coincidence and had nothing to do with the error. Thanks for the post!

    Comment by Trevor Evans — July 18, 2008 @ 7:50 pm


RSS feed for comments on this post. TrackBack URI

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 )

Facebook photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: