Может кто-нибудь, пожалуйста, проведите меня через вложенные атрибуты в Rails 3?
У меня есть две модели: сертификаты и хранители, связанные следующим образом:
Модель сертификата:
class Certificate < ActiveRecord::Base
belongs_to :shareholder
belongs_to :custodian
belongs_to :issuer
accepts_nested_attributes_for :custodian, :shareholder, :issuer
end
контроллер сертификата:
class CertificateController < ApplicationController
def issue
@certificate = Certificate.new
@certificate.custodian.build
end
end
My View:
<% form_for(:certificate, :url => {:action => 'testing'}) do |f| -%>
<div id="error">
<%= f.error_messages %>
</div>
<%= f.label :number, "Certificate Number" %>
<%= f.text_field :number %> <br/>
<%= f.label :num_of_shares, "Number Of Shares" %>
<%= f.text_field :num_of_shares %> <br/>
<% f.fields_for :custodian do |custodian| -%>
<%= custodian.label :name, "Custodian Name" %>
<%= custodian.text_field :name %>
<% end -%>
<%= f.submit "Issue Certificate", :disable_with => 'Working....' %>
<% end -%>
Теперь по какой-то причине в моем контроллере в строке 4: @certificate.custodian.build
I 'Я получаю эту ошибку: undefined method 'build' for nil:NilClass
Может ли кто-нибудь помочь, пожалуйста?