У меня есть класс User, который может иметь много платежей. Пользователь будет сохранен, а платежи - нет.
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
attr_accessor :payments, :payments_attributes
attr_accessible :payments_attributes, :payments
has_many :payments, :inverse_of => :user, :autosave => true
accepts_nested_attributes_for :payments, allow_destroy: false
end
class Payment < ActiveRecord::Base
# it looks that I do not need the attr_accessor methods
#attr_accessor :method, :paid, :amount, :creditcard, :security_code, :expires_at
attr_accessible :method, :paid, :amount, :creditcard, :security_code, :expires_at
attr_accessible :created_at, :user_id
belongs_to :user, :inverse_of => :payments
validates_presence_of :method
end
Я пробовал этот подход:
User.create!( { email: "[email protected]", payments: {paid: false, method: "bank"} } )
Есть ли решение сделать это без прохождения:
u = User.new(params)
u.payments(payments_params)
u.save!