I'm probably missing something trivial...
I have a User model that 'has_one' UserProfile:
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
before_create :create_remember_token
has_many :user_roles, dependent: :destroy
has_many :roles, through: :user_roles
has_one :user_profile, dependent: :destroy
accepts_nested_attributes_for :user_roles, :user_profile, allow_destroy: true
validates :email, presence: true, format: {with: TextUtils::VALID_EMAIL_REGEX}, uniqueness: {case_sensitive: false}
has_secure_password
validates :password, length: { minimum: 6 }
def User.new_remember_token
SecureRandom.urlsafe_base64
end
def User.digest(token)
Digest::SHA1.hexdigest(token.to_s)
end
def admin?
in_role?(Role::ADMINISTRATOR)
end
def in_role?(role)
!self.roles.find_by_name(role).nil?
end
private
def create_remember_token
self.remember_token = User.digest(User.new_remember_token)
end
end
and I have a UserProfile model that 'belongs_to' User:
class UserProfile < ActiveRecord::Base
belongs_to :user
has_one :address, dependent: :destroy
accepts_nested_attributes_for :address
validates :first, :last, :ssn, :title, :division, :phone_home, :phone_mobile, :phone_work, :phone_work_ext,
:emergency_phone, :emergency_name, :emergency_relation, presence: true
validates :personal_email, format: { with: TextUtils::VALID_EMAIL_REGEX }
end
When I try to seed the database as such (or any other way where profile is assigned to user):
# Admin
admin = User.create!(email: "admin@work.com", password: "secret", password_confirmation: "secret",
user_profile: UserProfile.new(
first: "Admin",
last: "User",
address_attributes: {line1: "123 Fake Street", line2: "Suite 1", city: "Some City", state: "FL", zip_code: "11111"},
ssn: "123-45-6789",
phone_work: "(111) 222-3333",
phone_work_ext: "110",
personal_email: "test@home.com")
)
I keep getting the following error:
rake aborted! ActiveRecord::UnknownAttributeError: unknown attribute: user_profile_id C:/work/Portal/db/seeds.rb:12:in `' Tasks: TOP => db:seed (See full trace by running task with --trace)
I'm at a loss as to why this is happening. Any help will be appreciated! I am using Rails 4.1.4, if that matters.