Felix
Felix

Reputation: 5629

Rails 4.0.0 errors in controller: ActiveRecord::SubclassNotFound

Hi I got this error in my Controller:

ActiveRecord::SubclassNotFound in CoursesController#create_course
Invalid single-table inheritance type: CourseTemplate is not a subclass of Course

The error occurs in this line:

course = Course.new(self.attributes)

what can I do to fix this ?

I've allready tried to do this in model:

self.inheritance_column = :_type_disabled

But then I got this error:

Mysql2::Error: Duplicate entry '4' for key 'PRIMARY': INSERT INTO `course_objects`

This error appears becaus the ID of the course_object is tried to use again, id is the PK

Upvotes: 0

Views: 99

Answers (1)

mohamed-ibrahim
mohamed-ibrahim

Reputation: 11137

You have to remove the id from the old object attributes:

obj_attributes = self.attributes
obj_attributes.delete("id") 
course = Course.new(obj_attributes)

Upvotes: 1

Related Questions