У меня есть две очень похожие модели. Предварительная обработка и диагностика, которые относятся к модели. Пациент:
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
show я показываю две формы: одну для 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| %>