I have an integer field 'fieldname'.
enum drop: ['a', 'b']
f.input :fieldname, as: select, collection: Model.drops
After selecting and submitting, I am getting error '0' is not a valid fieldname.
Currently making it work by writing setters for integer fields using enum like this:
def fieldname=(value)
self[:fieldname] = value.to_i
end
Can you tell me the proper way? I dont think writing this setter method is a good way.
Add .keys
to the collection definition:
f.input :fieldname, as: select, collection: Model.drops.keys
This way the option's value will be the same string as the text and on saving ActiveRecord will convert it to integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With