mongoid multi parameter attributes problem with date

随声附和 提交于 2019-12-23 06:56:43

问题


I have been following the mongoid railscast and I am facing a multi parameter attributes problem when i add a new field field :published_on, :type => Date

Article.find("4da14b1447640b14eb000002").published_on 
=> nil

but with Article.find('4da14b1447640b14eb000002')

=> published_on: nil, published_on(1i): "2011", published_on(2i): "6", published_on(3i): "10"

How do i get the desire output?

i know there is a temporary solution https://gist.github.com/315227

but the issue of this problem is closed and I have the latest 2.0.1 mongoid gem and yet the problem occur.


回答1:


Modify your Article class so it looks like the one below.

class Article
  include Mongoid::Document
  include Mongoid::MultiParameterAttributes

  ...
end



回答2:


In case you're using Mongoid 4.0 - the Mongoid::MultiParameterAttributes has been removed there.

If you need this functionality anyway you may take the classes from this blog.



来源:https://stackoverflow.com/questions/5610896/mongoid-multi-parameter-attributes-problem-with-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!