我尝试创建一个根据collection_select
以下是我开发的内容:
#new.html.erb
<%= form_for(@person) do |f| %>
<div class="field">
<%= f.label "Person type" %><br>
<%= f.collection_select :person_type, Reg.where(daw_tabla_id: 20), :idregtab, :reg_char, {:include_blank => true}, {:multiple => false, :id => "tipop", :data => {:remote => true}} %>
</div>
<% end %>
collection_select
给我选项0,1,2,3和4
基于选项选项,我想呈现_form.html.erb
部分,然后使用jquery或ajax呈现_form1.html.erb
或_form2.html.erb
...
render_js.js.erb
$.jQuery(function(){
$('#tipop').on('change',function() {
var val = document.getElementById('#tipop').value;
<%= j render 'form'%>
switch (val) {
case "1":
return <%= j render 'formestudent'%>;
case "2":
return console.log("val 2");
case "3":
return console.log("valor 3");
case "4":
return console.log("valor 4");
default:
return console.log("default");
}
});
});
有人能给我一个线索吗?