Rails实现了两级JQuery检查和取消检查父复选框的所有子复选框

Rails实现了两级JQuery检查和取消检查父复选框的所有子复选框,jquery,ruby-on-rails,checkbox,Jquery,Ruby On Rails,Checkbox,尝试实现多个父/子复选框集,其中“全部选中”将选中所有复选框,取消选中其中一个子复选框将取消选中所有复选框。已经在网上找到了几种解决方案,但没有一种是使用RubyonRails的。一个看起来很有前途的解决方案利用了简单的HTML和jQuery脚本。基本HTML如下所示:jQuery代码中引用了这些类以标识复选框: <html> <fieldset> <input type="checkbox" class="parentCheckBox" /&

尝试实现多个父/子复选框集,其中“全部选中”将选中所有复选框,取消选中其中一个子复选框将取消选中所有复选框。已经在网上找到了几种解决方案,但没有一种是使用RubyonRails的。一个看起来很有前途的解决方案利用了简单的HTML和jQuery脚本。基本HTML如下所示:jQuery代码中引用了这些类以标识复选框:

<html>
   <fieldset>
        <input type="checkbox" class="parentCheckBox" /> Parent 1<br />
        <input type="checkbox" class="childCheckBox" /> Child 1-1<br />
        <input type="checkbox" class="childCheckBox" /> Child 1-2<br />
        <input type="checkbox" class="childCheckBox" /> Child 1-3<br />
        <input type="checkbox" class="childCheckBox" /> Child 1-4<br />
        <input type="checkbox" class="childCheckBox" /> Child 1-5<br />
    </fieldset>
</html>
…并举例说明:

check_box("eula", "accepted", { class: 'eula_check' }, "yes", "no")
 # => <input name="eula[accepted]" type="hidden" value="no" />
 #    <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />  
…但我在这里抓住了救命稻草,因为我不确定定义、语法等。试图将上面的简单HTML翻译成rubyspeak,我得出了以下结论:

<fieldset>

  <div class="parentCheckbox">
    <%= f.label :checkall %><br>
    <%= f.check_box :checkall, {class: parentCheckBox} %>
  </div>
  <div class="childCheckBox">
    <%= f.label :date_one %><br>
    <%= f.check_box :date_one, {class: childCheckBox} %>
  </div>
  <div class="childCheckBox">
    <%= f.label :date_two %><br>
    <%= f.check_box :date_two, {class: childCheckBox} %>
  </div>
  <div class="childCheckBox">
    <%= f.label :date_three %><br>
    <%= f.check_box :date_three, {class: childCheckBox} %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %> 

</fieldset>  
…并出现以下错误:

undefined local variable or method `parentCheckBox' for #<#<Class:0xbdcb5e4>:0xc07ab8c>
Extracted source (around line #18):
15 
16 <div class="parentCheckbox">
17 <%= f.label :checkall %><br>
18 <%= f.check_box :checkall, {class: parentCheckBox} %>
19 </div>
我确信我在这里有点离题,但是API在将非常简单的HTML转换为嵌入式ruby方面几乎没有帮助。我知道jQuery脚本可以与HTML一起工作,但是我需要提交表单的结果来为数据库提供信息,而不仅仅是在显示中看起来很漂亮,所以我尽量不要太多地干扰rails生成的代码

迷路了

-添加到字符串“parentCheckBox”

<fieldset>

  <div class="parentCheckbox">
    <%= f.label :checkall %><br>
    <%= f.check_box :checkall, {class: parentCheckBox} %>
  </div>
  <div class="childCheckBox">
    <%= f.label :date_one %><br>
    <%= f.check_box :date_one, {class: childCheckBox} %>
  </div>
  <div class="childCheckBox">
    <%= f.label :date_two %><br>
    <%= f.check_box :date_two, {class: childCheckBox} %>
  </div>
  <div class="childCheckBox">
    <%= f.label :date_three %><br>
    <%= f.check_box :date_three, {class: childCheckBox} %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %> 

</fieldset>  
undefined local variable or method `parentCheckBox' for #<#<Class:0xbdcb5e4>:0xc07ab8c>
Extracted source (around line #18):
15 
16 <div class="parentCheckbox">
17 <%= f.label :checkall %><br>
18 <%= f.check_box :checkall, {class: parentCheckBox} %>
19 </div>