ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass
type
is restricted word, you can't use it as a column name in ActiveRecord models (unless you're doing STI).
Try using inheritance_column, then type will no longer be reserved:
class Category < ActiveRecord::Base
self.inheritance_column = :foo
attr_accessible :type
has_many :products
end
class Product < ActiveRecord::Base
attr_accessible :category_id, :color, :price, :title
belongs_to :category
end
Just came across this post while trying to find a solution to my own problem with this type
reserve word so maybe this can help someone else.
Changing the name of the column isn't an easy solution for me because I'm working on a existing complete system migrating to active record from mongodb.
I found adding self.inheritance_column = :_type_disabled
to the model with the offending column name fixed the error which I found here.
Disable STI
I had to add “self.inheritance_column” as opposed to simply “inheritance_column” to get this to work. Code example
class MyModel < ActiveRecord::Base # disable STI
self.inheritance_column = :_type_disabled end
I know that we're not using any inheritance so I think it's fine for me to do this but I don't know what other implications there could be because of it. If anyone else has any opinions on this I'd be interested to know.
If you can just change the column name and avoid doing this then that's a much better solution I'm sure.