1

我有一个简单的表格,可让您选择用户并选择医院。表单成功提交。但是,当我查看 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 %>
4

1 回答 1

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

于 2013-01-13T23:02:38.060 回答