Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.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
Ruby on rails 将集合中的每一对复选框包装在一个div中_Ruby On Rails - Fatal编程技术网

Ruby on rails 将集合中的每一对复选框包装在一个div中

Ruby on rails 将集合中的每一对复选框包装在一个div中,ruby-on-rails,Ruby On Rails,我想将集合\u复选框生成的两个后续复选框包装成一个 例如,正常的收集\u复选框输出为: <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" /> <label for="post_author_ids_1">D. Heinemeier Hansson</label> <input id="post_autho

我想将
集合\u复选框
生成的两个后续复选框包装成一个

例如,正常的
收集\u复选框
输出为:

<input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
<label for="post_author_ids_1">D. Heinemeier Hansson</label>
<input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
<label for="post_author_ids_2">D. Thomas</label>
<input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" />
<label for="post_author_ids_3">M. Clark</label>
<input name="post[author_ids][]" type="hidden" value="" />

海涅迈尔·汉森博士
D.托马斯
克拉克先生
我想实现的是:

<div class="row">
    <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
    <label for="post_author_ids_1">D. Heinemeier Hansson</label>
    <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
    <label for="post_author_ids_2">D. Thomas</label>
</div>
<div>
    <input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" />
    <label for="post_author_ids_3">M. Clark</label>
    <input name="post[author_ids][]" type="hidden" value="" />
</div>

海涅迈尔·汉森博士
D.托马斯
克拉克先生
据我从代码中看到,这是不受支持的-样式只能应用于单个项目

假设monkey patching不是一个选项,因为它将影响全球的帮助者,那么还有什么其他选项可以实现此效果

我认为您是正确的,不支持在复选框输入之间插入
。不过,生成的输入框确实有不同的ID

<input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
<label for="post_author_ids_1">D. Heinemeier Hansson</label>
<input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
<label for="post_author_ids_2">D. Thomas</label>
<input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" />
<label for="post_author_ids_3">M. Clark</label>
<input name="post[author_ids][]" type="hidden" value="" />

海涅迈尔·汉森博士
D.托马斯
克拉克先生

我真的不知道你想要实现什么,因为你没有描述它。尽管如此,如果您试图将相同的样式添加到一对项目中,您可以枚举这些ID以应用适当的样式。

请给出一个示例,将两个后续复选框分别换行是什么意思?