我有一个表单,其中包含下拉列表和文本字段等字段。在提交表单并返回一些错误后,我们在fields_for下定义的字段不会被填充。如何保留用户在提交表单之前选择的值在fields_for?
上这是我的观点代码:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= f.text_field :firstname, class: "input-text personal ", placeholder: 'FIRSTNAME' %>
<%= f.text_field :lastname, class: "input-text personal", placeholder: 'LASTNAME' %>
<%= f.fields_for :doctor do |p| %>
<%= p.collection_select(:specialization_id, Specialization.order(:order), :id, :description, {include_blank: ''}, class: "js-specialization js-select2", id: "specialization-select", "data-placeholder" => "SPECIALIZATION")%>
<%= p.collection_select(:institution_id, Institution.order(:order), :id, :description, {include_blank: '', selected: params[:institution_id]}, class: "js-institution js-select2", id: "institution-select", "data-placeholder" => "INSTITUTION") %>
<%= p.text_field :license_number, class: "input-text personal ", placeholder: 'LICENSE NUMBER' %>
</div>
<% end %>
<% end %>