I have a class/model called User which (using Single table inheritance) has a subclass called Student (among others)
Student has a 'has_one' association with 'HomeAddress' which is a subclass of 'Place'
My model 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 Students controller, I'm trying to create a new Student and associated HomeAddress to pass through to my view:
class StudentsController < ApplicationController
def new
@student = Student.new
@student.build_home_address
end
however, I get an error:
:uninitialized constant Student::HomeAddress
This issue is clearly with the line @student.build_home_address but I don't understand why it's causing this error. I've checked all of naming conventions (i.e. models, controllers, associations) and have other nested attributes relationships working in my app. Perhaps there is an issues with having nested attributes for an STI subclass? (i.e. HomeAddress)
Let me know if you would like to see any other code. Thanks.