我有两个非常相似的模型预处理和诊断,属于模型患者:
class Pretreatment < ActiveRecord::Base
belongs_to :patient
attr_accessible :content
end
class Diagnosis < ActiveRecord::Base
belongs_to :patient
attr_accessible :content
end
class Patient < ActiveRecord::Base
attr_accessible :age, :name, :city, :street, :number
has_many :anamneses
has_many :befunds
end
在Patient
显示页面上,我显示了两种形式,一种用于 the Preatreatment
,另一种用于Diagnosis
:
<%= form_for([@patient, @patient.preatreatments.build]) do |f| %>
<div class="field">
<%= f.label :conten %><br />
<%= f.text_field :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<%= form_for([@patient, @patient.diagnosiss.build]) do |f| %>
<div class="field">
<%= f.label :content %><br />
<%= f.text_field :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我的问题是如何将两个表单放在一起,以便用户只需按一次提交按钮?我m not sure but I think nested attributes is not the right thing to handle it, maybe the
fields_for`标签?
更新我尝试使用fields_for
标签:
<%= form_for([@patient, @patient.pretreatment.build]) do |f| %>
<div class="field">
<%= f.label :content %><br />
<%= f.text_field :content %>
</div>
<%= fields_for([@patient, @patient.diagnosiss.build]) do |u| %>
<div class="field">
<%= u.label :content %><br />
<%= u.text_field :content %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
但我得到了错误:
undefined method `model_name' for Array:Class in <%= fields_for([@patient,@patient.befunds.build]) do |u| %>