Rails error: syntax error, unexpected tINTEGER Object::1

When trying to do a model.find(), I ran into the error, 'syntax error, unexpected tINTEGER Object::1'. If you have a table that uses a magic or reserved name, such as type, you will get this error. This error was a pain in the ass, but I figured out that you can get by it:

class SomeModel < ActiveRecord::Base
  self.inheritance_column = ''

The inheritance_column override is the key, basically giving it a different value to use. Hope this helps!

You have a nil object when you didn’t expect it!

I found this cool little snippet of code somewhere on the internet. Anywhere you access an object in a view, adding the following will ensure the page doesn’t blow up:

<%= @object.association.variable rescue nil %>

Of course, you won’t know if you have an error now either.

%d bloggers like this: