ruby-on-rails – 不能将datetime_select与Mongoid一起使用

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 不能将datetime_select与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.

我经常遇到的解决方案是在模型中包含Mongoid :: MultiParameterAttributes.不幸的是,该模块已被删除https://github.com/mongoid/mongoid/issues/2954

我已经尝试过分配gem并重新添加MultiparameterAttributes模块,但gem不会从lib文件中读取代码.有没有办法将DateTime_select与Mongoid一起使用?

解决方法

您需要在Mongoid模型中包含include Mongoid :: MultiParameterAttributes.

this GitHub issue on the problem.

我无法在任何地方找到它.-

这会教我不正确阅读! This gem seems to be the solution though.

猜你在找的Ruby相关文章