问题
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']] %>
I forgot to mention, the error I'm getting when I try to load this page is
wrong number of arguments (2 for 4)
回答1:
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.
Right from this example below:
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
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:
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
来源:https://stackoverflow.com/questions/17242668/wrong-number-of-arguments-2-for-4-using-simple-form-checkboxes