2014-09-21 57 views
2

我们刚刚从rails ActiveRecord迁移到mongoid。我们认为,我们可以使用助手Rails 4&Mongoid:日期助手

<%= f.date_select :date, :use_two_digit_numbers => true, :order => [:day, :month, :year], class: "form-control" %> 

但是它不与mongoid工作,因为它正在发送参数

date(3i)"=>"21", "date(2i)"=>"9", "date(1i)"=>"2014" 

和Rails抛出

Mongoid::Errors::UnknownAttribute 
Problem: Attempted to set a value for 'date(3i)' which is not allowed on the model 

This question提到mongoid不能这样做,而不包括一个模块。但显然我的导轨应用程序不识别模块?

uninitialized constant Mongoid::MultiParameterAttributes 

回答

0

在mongoid版本5中,看起来多个参数已被放弃。

现在我在视图中使用html5标记,如date_field_tag,在控制器操作(创建,更新)中,我在对象保存到数据库之前添加了一个像@article.write_attribute(:published_on, params[:published_on])这样的手动操作。

虽然这是一个丑陋的解决方案,它的工作原理。