我有一个简单的表单,允许您选择用户并选择医院。表单成功提交。但是当我查看index.html.erb时,它看起来如下:[imgur] [1]。知道为什么“全名”和“医院”没有出现?
<div class="field">
<%= f.label :booking_reference %>
<br/>
<%= f.text_field :booking_reference %>
</div>
<div class="field">
<%= fields_for :User do |user| %>
<%= user.collection_select :user_id, User.all, :id, :full_name %>
<% end %>
</div>
<div class="field">
<%= fields_for :hospital do |hosp| %>
<%= hosp.collection_select :hospital_id, Hospital.all, :id, :name %>
<% end %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
答案 0 :(得分:0)
不会像
那样<div class="field">
<%= f.collection_select :hospital_id, Hospital.all, :id, :name %>
</div>
和
<div class="field">
<%= f.collection_select :user_id, User.all, :id, :full_name %>
</div>
否则你打破了表单助手。
有疑问,请查看api:collection_select