开发者

Rails standard date selector results in nil date values in model

I am sure this is really simple, but I'm missing something. This has always worked before. I'm using Mongoid on Rails 3.1.

a = {"title"=>"bad2", "starts_at(1i)"=>"2011", "starts_at(2i)"=>"9", "starts_at(3i)"=>"12", "starts_at(4i)"=>"10", "starts_at(5i)"=>"49", "ends_at(1i)"=>"2011", "ends_at(2i)"=>"9", "ends_at(3i)"=>"12", "ends_at(4i)"=>"11", "ends_at(5i)"=>"49", "all_day"=>"0", "description"=>"foo2"} 
e = Event.new(a)
 => #<Event _id: 4e6d765af11aac06e8000004, _type: nil, created_at: nil, updated_at: nil, title: "bad2", starts_at: nil, ends_at: nil, all_day: false, description: "foo2", starts_at(1i): "2011", starts_at(2i): "9", starts_at(3i): "12", starts_at(4i): "10", starts_at(5i): "49", ends_at(1i): "2011", ends_at(2i): "9", ends_at(3i): "12", ends_at(4i): "11", ends_at(5i): "49"> 
ruby-1.9.2-p290 :020 > e.valid?
 => true 
ruby-1.9.2-p290 :021 > e.save
 => true 
ruby-1.9.2-p290 :022 > e.starts_at
 => nil 
ruby-1.9.2-p290 :023 > e.ends_at
 => nil 

All rel开发者_运维技巧evant code is here: https://gist.github.com/1210498


The multiparameter attributes code that make the date helper work came from ActiveRecord, and was not originally implemented in Mongoid. It is now, but you have to explicitly require it. This is so those that do not use it don't incur the performance penalties.

class Event
  include Mongoid::Document
  include Mongoid::MultiParameterAttributes
  ...
end

The relevant code is here:
https://github.com/mongoid/mongoid/blob/master/lib/mongoid/multi_parameter_attributes.rb

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜