Ниже приведен упрощенный вид двух моих моделей: «Пользователь» и «Пациент».
Пользователь имеет_ одного пациента, а пациент принадлежит_ пользователю.
В консоли rails я пытаюсь сделать следующее:
p = Patient.new(:user_id => 2, :user_attributes => [{:username => 'patient'},{:password => 'password'}])
Я получаю ошибку:
NoMethodError: неопределенный метод `with_indifferent_access 'для [{: username =>" пациент "}, {: пароль =>" пароль "}]: массив
Что я делаю не так?
Ниже представлены две модели:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# username :string(255)
# encrypted_password :string(255)
# salt :string(255)
# active :boolean
# disabled :boolean
# last_login :time
# first_name :string(255)
# last_name :string(255)
# address1 :string(255)
# address2 :string(255)
# city :string(255)
# state :string(255)
# postcode :string(255)
# phone :string(255)
# cell :string(255)
# email :string(255)
# created_at :datetime
# updated_at :datetime
#
class User < ActiveRecord::Base
has_one :patient
attr_accessible :username, :password, :active, :disabled, :first_name, :last_name,
:address1, :address2, :city, :state, :postcode, :phone, :cell, :email
attr_accessor :password
end
# == Schema Information
#
# Table name: patients
#
# id :integer not null, primary key
# user_id :integer
# created_at :datetime
# updated_at :datetime
#
class Patient < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user
attr_accessible :user_id, :user_attributes
end