title: Rails 4: How to Disable Text Field Based on Checkbox Value Using JQuery in Rails
body: <p>I have a check box and a text field in a form.  If the checkbox is checked, I want to disable the field (and if it's unchecked, I want it to be enabled).</p>
  
  <p>I tried to write some jQuery based on the second answer for this question:
  <a href="https://stackoverflow.com/questions/2330209/jquery-checkbox-enable-disable">jQuery - checkbox enable/disable</a></p>
  
  <p>However, the text field is (foo_price) is disabled when the page loads even though the field is unchecked.  What am I doing wrong?</p>
  
  <p>I'm using the <a href="https://github.com/plataformatec/simple_form" rel="nofollow noreferrer">Simple Form gem</a>:</p>
  
  <pre><code>&lt;%= simple_form_for @foo do |f| %&gt;
    &lt;%= f.input :free_flag, as: :boolean %&gt;
    &lt;%= f.input :price  %&gt;
  
    &lt;%= f.button :submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The form renders:</p>
  
  <pre><code>&lt;form&gt;
    &lt;input class="boolean optional" type="checkbox" value="1" name="foo[free_flag]" id="foo_free_flag" /&gt;
    &lt;input class="numeric decimal optional" type="number" step="any" value="12.99" name="foo[price]" id="foo_price" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My Coffeescript:</p>
  
  <pre><code>enable_cb = -&gt;
    $('#foo_price').prop 'disabled', !@checked
    return
  
    $ -&gt;
      enable_cb()
      $('#foo_free_flag').click enable_cb
      return
  </code></pre>