Use hash as source for collection_check_boxes
I have the following hash:
FIELD_LIST = {
-1 => 'User',
-2 => 'Duration',
-3 => 'Price',
-4 => 'Invoiced'
}
I want to use this with collection_check_boxes.
The manual says:
The parameters: value_method and: text_method are methods to be called for each member of the collection.
So I tried this:
= f.collection_check_boxes TimesheetReport::FIELD_LIST, [0], [1], :input_html => { :class => 'checkbox' }
But this is giving me an error.
How can a hash be used as input to create checkboxes?
+3
source to share
1 answer
Actually, it is possible. A hash is technically a collection of objects. You can do something like this:
= f.collection_check_boxes :field_name, TimesheetReport::FIELD_LIST, :first, :last, :input_html => { :class => 'checkbox' }
Replace with the :field_name
actual name of your attribute where you want to store this data. It should work.
+4
source to share