我的项目需要一些帮助。我想要做的是只要有所选的call_field可用,就显示suballtype_field(grouped_collection_select),否则应该隐藏suballtype_field。
这是我的form.html.erb
<h2>New incoming call</h2>
<%= form_for(@call) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.collection_select :calltype_id, Calltype.order(:id), :id,
:name, :prompt => "Type of call" %>
<%= f.grouped_collection_select :subcalltype_id, Calltype.order(:id),
:subcalltypes, :name, :id, :subname, include_blank: true %>
<%= f.text_area :content, placeholder: "What was your call regarding?" %>
<%= f.submit "Submit", class: "btn btn-primary" %>
<% end %>
这是我的call.coffee文件
jQuery ->
subcalltypes = $('#call_subcalltype_id').html()
$('#call_calltype_id').change ->
calltype = $('#call_calltype_id :selected').text()
options = $(subcalltypes).filter("optgroup[label='# {calltype}']").html()
if options
$('#call_subcalltype_id').html(options)
else
$('#call_subcalltype_id').empty()
我不熟悉咖啡脚本和jQuery。难道我做错了什么?帮助
提前致谢。干杯! :)