Has_one through and accepts_nested_attributes_for
I am trying to create a form to edit an object 2 associated with a has_one relationship via:
bank_acount.rb
class BankAccount < ActiveRecord::Base
belongs_to :user, inverse_of: :bank_account
has_one :personal_information, through: :user
accepts_nested_attributes_for :personal_information
accepts_nested_attributes_for :user
#...
end
personal_information.rb
class PersonalInformation < ActiveRecord::Base
belongs_to :user, inverse_of: :personal_information
#...
end
user.rb
class User < ActiveRecord::Base
has_one :personal_information, inverse_of: :user
has_one :bank_account, inverse_of: :user
accepts_nested_attributes_for :personal_information
#...
end
When I try to submit my form (here is a test to emulate this)
bank_account.update({:iban => 'XXX', :bic => 'XXX', personal_information_attributes: {
first_name: 'first name',
last_name: 'last name',
address: 'address',
zip: 'zip',
city: 'city'
}})
I am getting this error:
ArgumentError: Cannot build association `personal_information'. Are you trying to build a polymorphic one-to-one association?
I don't do anything with polymorphic things and I don't know where this error comes from.
Any idea?
+3
source to share
No one has answered this question yet
Check out similar questions: