Nested Attributes in Rails 3

前端 未结 3 728
忘掉有多难
忘掉有多难 2020-12-11 07:09

can anyone please walk me through Nested Attributes in Rails 3?

I have two Models: Certificates and Custodians, related as follows:

Certificate Model:

<
3条回答
  •  难免孤独
    2020-12-11 07:27

    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.

提交回复
热议问题