title: Rails Want to add fields to a form based on response of boolean entry
body: <p>I'm building a Rails 4 app and I want to add an if/then/else statement to a form. If the Boolean element is YES, then show X, else show Y. I seem to have run down a Coffee script rabbit hole and not sure I'm on the right track or not. I copied and pasted elements from another answer and have tried to use it it in a brand new rails app. It has not worked for me ever.</p>
  
  <p>In my views ....views/invoices/_form.html.erb I have:</p>
  
  <pre><code>&lt;label class="checkbox"&gt;
   &lt;input id="user_holiday_ids_" name="user[holiday_ids][]" type="checkbox" value="2" /&gt;
   Valentine Day
  &lt;/label&gt;
  &lt;div style="display:none;"&gt;
      Whatever you need here&lt;input type="text" id="foo" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In my javascripts/invoices.js.coffee I have:</p>
  
  <pre><code>$(".checkbox").click -&gt;
    $(this).next("div").toggle()
    return
  </code></pre>
  
  <p>In application.js I have (have not touched defaults...):</p>
  
  <pre><code>//= require jquery
  //= require jquery_ujs
  //= require twitter/bootstrap
  //= require turbolinks
  //= require_tree .
  </code></pre>
  
  <p>The checkbox is created, but the hidden form item does not toggle between hidden and show. I know it must be basic, but what am I doing wrong?</p>
  
  <p>EDIT: Here is the revised code that still does not work....</p>
  
  <pre><code>&lt;div id="use_po"&gt;
      &lt;%= f.label :use_po %&gt;&lt;br&gt;
      &lt;%= f.check_box :use_po %&gt;
  &lt;/div&gt;
  
   &lt;div id="po_num_num"&gt;
      &lt;%= f.label :po_number %&gt;&lt;br&gt;
   &lt;%= collection_select(:invoice, :po_id, Po.all, :id, :po_num, prompt: true) %&gt;
  &lt;/div&gt;
  
  
  $("#use_po").change -&gt;
    if $(this).is(":checked")
      $("#po_num_num").show()
    else
      $("#po_num_num").hide()
    return
  </code></pre>