我正在使用 Rails 3.2.11、mongoid 3.1.2 并设计 2.2.3,并且我有一个带有生日日期字段的用户模型。
class User
include Mongoid::Document
field :birthday, type: Date
field :email, type: String, default: ""
field :encrypted_password, type: String, default: ""
field :remember_created_at, type: Time
attr_accessible :email, :password, :password_confirmation, :remember_me, :birthday
devise :database_authenticatable, :registerable, :rememberable, :validatable
validates_presence_of :email, :birthday
...
end
我在注册表单中添加了一个生日字段,如下所示:
f.input :birthday, :as => :date, :start_year => (Date.current - 5.year).year, :end_year => (Date.current - 120.year).year, :include_blank => true
问题是,当我注册时,我总是收到错误消息:生日不能为空。
当我查看日志时,我看到:
Started POST "/users" for 127.0.0.1 at 2013-04-22 13:58:27 +0200
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Cmjq47KqHWzEoytGxH+L5s5zbWrHYDZn221Dq6+wVQQ=", "user"=>{"email"=>"lalala@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "birthday(3i)"=>"25", "birthday(2i)"=>"11", "birthday(1i)"=>"1984"}
所以我不明白为什么它不起作用:(我已经在谷歌上搜索了几个小时而没有任何机会。我虽然它可能来自 mongoid 的批量分配或设计 build_ressource 但我没有找到任何解决方案。你已经得到这个问题了吗?