Jam*_*cel 8 ruby ruby-on-rails mongodb mongoid
每次我尝试在视图中使用Datetime_select时,应用程序都会抛出属性错误.
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.
Run Code Online (Sandbox Code Playgroud)
我经常遇到的解决方案是在模型中包含Mongoid :: MultiParameterAttributes.不幸的是,该模块已被删除!https://github.com/mongoid/mongoid/issues/2954
我已经尝试过分配gem并重新添加MultiparameterAttributes模块,但gem不会从lib文件中读取代码.有没有办法在Mongoid中使用DateTime_select?
您需要包含include Mongoid::MultiParameterAttributes
在您的 Mongoid 模型中。
有关该问题,请参阅此 GitHub 问题。
没找到具体的记录~
这将教会我不正确阅读!不过,这颗宝石似乎是解决方案。