Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Rails中的CoffeeScript基于集合选择切换div_Jquery_Html_Ruby On Rails_Forms_Coffeescript - Fatal编程技术网

Jquery Rails中的CoffeeScript基于集合选择切换div

Jquery Rails中的CoffeeScript基于集合选择切换div,jquery,html,ruby-on-rails,forms,coffeescript,Jquery,Html,Ruby On Rails,Forms,Coffeescript,我有一个Rails应用程序,它使用了一些基本的表单,我需要一些咖啡脚本的帮助。以下是我的表格代码摘录: <%= f.label :Patient_Insurance, "Patient Insurance", class: "control-label" %> <%= f.collection_select(:insurance_id, Insurance.order("insurance_type ASC"), :id, :insurance_type, {:incl

我有一个Rails应用程序,它使用了一些基本的表单,我需要一些咖啡脚本的帮助。以下是我的表格代码摘录:

  <%= f.label :Patient_Insurance, "Patient Insurance", class: "control-label" %>
  <%= f.collection_select(:insurance_id, Insurance.order("insurance_type ASC"), :id, :insurance_type, {:include_blank => true}, {:class => 'select'}) %></br>
  <div id="medicaid_fax_number">
      <%= f.label :medicaid_fax_number %>
      <%= f.text_field :medicaid_fax_number, placeholder: '2812224444' %>
  </div>

true},{:class=>select'})%>
我想做的是保持
medicaid\u fax\u number
字段始终隐藏,除非用户从集合中选择“medicaid”,然后显示div

我对JS和Coffee脚本非常生疏,所以我真的需要一只手来处理这个脚本。我知道我正在关注的变化是
call\u insurance\u id
(保险托收选择表单中的id)。但我不确定在coffeescript中如何评估该值是否等于“Medicaid”


我将继续做更多的研究并继续努力,但我认为这里的人比我更了解情况。

对于动态解决方案,在您向保险模型中添加一个类似于“需要医疗救助”和“传真号码”的列,类型为布尔值。您可以通过以下方式进行更新:

.erb

<%= f.label :Patient_Insurance, "Patient Insurance", class: "control-label" %>
<%= f.select :insurance_id, {include_blank: "Select"}, class: "select" do %>
  <%= options_for_select(Insurance.order("insurance_type ASC").map {|k, v| [k.insurance_type.humanize, k.id, {show_medicaid_fax_number: k.need_medicaid_fax_number?}]}, f.object.insurance_id, )%>
<%= end %>
</br>
<div id="medicaid_fax_number">
    <%= f.label :medicaid_fax_number %>
    <%= f.text_field :medicaid_fax_number, placeholder: 'Fax number' %>
</div>

这工作得很好,但是我必须将保险类型的ID硬编码到CoffeeScript中。我真的希望能够根据字符串“Medicaid”进行评估。有人能帮忙吗?

谢谢你的提示,但这对我不起作用。我做了Chrome检查,没有在控制台中看到错误,所以我不确定问题出在哪里。查看我发布到“我要工作的内容”中的答案。它在保险ID之外进行评估,但我想在字符串“Medicaid”之外进行评估。如果你能帮忙,请告诉我。
$ ->
  $('#call_insurance_id').change ->
    option = $(this).find('option:selected')
    if option.attr("show_medicaid_fax_number") is "true"
      $('#medicaid_fax_number').show()
    else
      $('#medicaid_fax_number').hide()
  $ ->
  $('#call_insurance_id').change ->
    if $(this).val() is "12"
      $('#medicaid_fax_number').show()
    else
      $('#medicaid_fax_number').hide()