Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use datetime_select with Mongoid

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?

like image 603
James Strocel Avatar asked Jun 03 '13 23:06

James Strocel


1 Answers

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.

like image 64
jordelver Avatar answered Sep 30 '22 06:09

jordelver