can anyone please walk me through Nested Attributes in Rails 3?
I have two Models: Certificates and Custodians, related as follows:
Certificate Model:
<accepts_nested_attributes_for should go on the side of one in the one-to-many relationship.
class Custodian < ActiveRecord::Base
has_many :certificates
accepts_nested_attributes_for :certificates
end
So, in your view, there should be no fields_for :custodian, it's on the wrong side. If you have to build a certificate from that view, you have to list custodians available, probably in a select box.
This line
<% f.fields_for :custodian do |custodian| -%>
should be
<%= f.fields_for :custodian do |custodian| -%>
With a belongs_to, it should be
@certificate.build_custodian