我有一个简单明了的要求。
Donations
是Church
的孩子。
教会 - 模式
class Church < ActiveRecord::Base
belongs_to :user, :class_name => 'User', :foreign_key => 'user_id'
has_many :donations
accepts_nested_attributes_for :donations
end
教会 - 控制者
class ChurchesController < ApplicationController
def show
# @church = Church.friendly.find(params[:id])
@church = Church.find(params[:id])
donations = @church.donations.build
end
捐赠 - 模型
class Donation < ActiveRecord::Base
belongs_to :church, :class_name => 'Church', :foreign_key => 'church_id'
end
这是问题。我在视野中看到了什么/ churches / show.erb
<%= form_for(@church ,url: church_path(@church), html: { method: :put }) do |f| %>
<%= f.fields_for :donations do |d| %>
<div class="content">...</div>
<% end %>
<% end %>
现在我的麻烦是div.content正在重复保存的'n'个捐赠记录。请帮助
答案 0 :(得分:1)
Donation.new
执行| d | %GT;
没有Donation.new,它只是显示现有记录和新表格。