Uninitialized constant when using nested attributes in STI subclass
I have a class / model called User which (using single table inheritance) has a subclass called Student (among others)
The student has an association of 'has_one' with 'HomeAddress' which is a subclass of 'Place'
My model is set up:
class User < ActiveRecord::Base
end
class Student < User
has_one :home_address, :dependent => :destroy
accepts_nested_attributes_for :home_address
end
class Place < ActiveRecord::Base
end
class HomeAddress < Place
belongs_to :student
end
In my student manager, I am trying to create a new student and associated HomeAddress to navigate to my view:
class StudentsController < ApplicationController
def new
@student = Student.new
@student.build_home_address
end
however, I am getting the error:
:uninitialized constant Student::HomeAddress
This issue is clearly related to the @ student.build_home_address line, but I don't understand why it is causing this error. I have checked all the naming conventions (e.g. models, controllers, associations) and other nested attribute relationships working in my application. Perhaps there is a problem with having nested attributes for the STI subclass? (i.e. HomeAddress)
Let me know if you want to see any other code. Thank.
source to share
No one has answered this question yet
Check out similar questions: