我是 Rails 的新手,我正在开发一个应用程序,该应用程序需要在需要时由医生更新的表格中显示患者信息。As soon I can select a patient from a list from sidebar I want to display first just an empty form and when a patient is selected all the info will be displayed on it.
我猜想这样做的唯一方法是首先将表单显示为空,然后,一旦选择了患者,就在控制器上捕获患者并重新加载页面以允许表单获取患者信息。
有人有更好的主意吗?否定答案:如何显示空表单?
在此先感谢您的时间。
此致。
更新:这是我试图在页面上展示的表格。@patient 是一个实例变量,一旦显示页面,它还没有定义。一旦医生从侧面的列表中选择一名患者,它就会显示出来。
<div class="row">
<div class="span6">
<%= render 'shared/error_messages' %>
<div>
<%= form_for(@patient) do |p| %>
<%= text_field_tag 'patient[name][]', nil, :placeholder => "name", :style =>height:12px;font-size:10px;" %>
<%= text_field_tag 'patient[name][]', nil, :placeholder => "surname", :style =>"height:12px;font-size:10px;" %>
<%= p.text_field :email, :placeholder => "email", :style => height:12px;font-size:10px;" %>
<%= p.text_field :phone, :placeholder => "phone", :style => height:12px;font-size:10px;" %>
<%= check_box_tag :active %>
<%= check_box_tag :sex, 'male' %>
<%= check_box_tag :sex, 'female' %>
<%= chack_box_tag :dao %>
<%= p.submit "Sumbit", class: "btn btn-small btn-primary pull-right", id: "boton" %>
<% end %>
</div>
</div>
</div>
这就是问题所在。由于控制器上的 @patient=nil 被选中,因此页面崩溃。
再次感谢。