Every time I try to use Datetime_select in a view, the app throws an attribute error.
Mongoid::Errors::UnknownAttribute:
Problem:
Attempted to set a value for 'fromtime(1i)' which is not allowed on the model Event.
Summary:
Without including Mongoid::Attributes::Dynamic in your model and the attribute does not already exist in the attributes hash, attempting to call Event#fromtime(1i)= for it is not allowed. This is also triggered by passing the attribute to any method that accepts an attributes hash, and is raised instead of getting a NoMethodError.
Resolution:
You can include Mongoid::Attributes::Dynamic if you expect to be writing values for undefined fields often.
The solution I come across most often was to include Mongoid::MultiParameterAttributes in the model. Unfortunately that module has been removed! https://github.com/mongoid/mongoid/issues/2954
I have tried forking the gem and re-adding the MultiparameterAttributes Module, but the gem won't read the code from the lib file. Is there any way to use DateTime_select with Mongoid?
You need to include include Mongoid::MultiParameterAttributes
in your Mongoid model.
See this GitHub issue on the problem.
I couldn't find it documented anywhere in particular.~
That'll teach me for not reading properly! This gem seems to be the solution though.
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