1
간단한 중첩 모델 양식을 설정하려고하지만 '새'동작을 통해 양식을 표시하려고 할 때 오류가 발생합니다. 여기 내 설정은 다음과 같습니다중첩 된 모델 양식
class Account < ActiveRecord::Base
has_many :people
has_many :organizations
accepts_nested_attributes_for :organizations
end
class Organization < ActiveRecord::Base
belongs_to :account
has_many :locations
accepts_nested_attributes_for :people
accepts_nested_attributes_for :addresses
end
class AccountsController < ApplicationController
def new
@account = Account.new
@account.organizations.build
end
def create
@account = Account.new(params[:account])
if @account.save
#handle success
else
render 'new'
end
end
end
<%= form_for(@account) do |f| %>
<%= f.label :type %><br />
<%= f.text_field :type %><br />
<%= f.fields_for :organization do |organization_fields| %>
<%= organization_fields.label :name %><br />
<%= organization_fields.text_field :name %><br />
<%= organization_fields.label :website %><br />
<%= organization_fields.text_field :website %><br />
<% end %>
<%= f.submit "Add account" %>
<% end %>
계정 /에서 '새로운'조치를 칠 시도/I는 다음과 같은 오류를 얻고 새로운 :
초기화되지 않은 상수 계정 : 조직
응용 프로그램 추적 : app/controllers/accounts_controller.rb : 5 : 'new'
모든 도움을 주실 수 있습니다.
오류가 발견되었습니다. 내 조직 모델에서 accepts_nested_attributes_for : 위치를 추가하고 작동합니다. 어리석은 실수. 당신의 도움을 주셔서 감사합니다. –