使用simple_form复选框错误的参数数(2为4) [英] Wrong number of arguments (2 for 4) using simple_form checkboxes
问题描述
我有点困惑的阅读我的simple_form关于一个复选框的集合。也就是说,除了我的选择之外,我还希望把什么放在这条线上。自述有:first,:last
,但并没有真正解释这些字服务器的目的。
I'm a little confused by the read me for simple_form in regards to a collection of check boxes. Namely, what else am I expected to put on the line besides my options. The readme has :first, :last
but doesn't really explain what purpose those words server.
我想要两个不同的复选框的集合。我还应该提到,每个复选框都与数据库中的布尔字段相关,并且它们的标签与列名称相同。
Below are two different collections of checkboxes I'd like to have. I should also mention, each checkbox relates to a boolean field in the DB and they are labeled the same as the column names.
<%= f.collection_check_boxes :options, [[false, 'App'], [false, 'DB'], [false, 'WCF']] %>
<%= f.collection_check_boxes :options, [[false, 'Com1'], [false, 'Com2'], [false, 'BofA']] %>
我忘了提及,当我尝试加载此页面时, p>
I forgot to mention, the error I'm getting when I try to load this page is
wrong number of arguments (2 for 4)
推荐答案
这个错误只是意味着你的<%= f.collection_checkboxes%>
2参数,但你给它4.记住这个以后的参考,因为这个错误很容易做。
This error simply mean that your <%= f.collection_checkboxes %>
takes 2 arguments but your giving it 4. Remember this for future reference as this mistake can be easily made.
从下面的示例开始:
form_for @user do |f|
f.collection_check_boxes(
:options, [[true, 'Yes'] ,[false, 'No']], :first, :last
) do |b|
b.label { b.check_box + b.text }
end
end
rubydoc.info网站声明如下:
The rubydoc.info website states the following:
也可以给出一个应该生成复选框的块+标签。要包装带有标签的复选框,例如上面的:
It is also possible to give a block that should generate the check box + label. To wrap the check box with the label, for instance as above:
所以从我的理解这个 :第一
和:last
表示标签。所以你有两个复选框。这是 true
或 false
,但是在选项数组之外,你提供了类的那些实例的标签。所以让我们举个例子。这为标签提供类 User >的实例
:第一
和:last
code>。希望这澄清的东西。链接如下:
So from my understanding of this the :first
and :last
represent the labels as it were. So that you'd have two check boxes. That are either true
or false
but then outside that option array you are providing the label those instances of the class. So lets take this example. That is providing the label the instances :first
and :last
of the class User
. Hope this clarifies things. The link is provided below:
Ruby Doc- SimpleForm collection_check_boxes
这篇关于使用simple_form复选框错误的参数数(2为4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!