自从开始使用 validates_timeliness gem 以来,我经常收到以下异常
Message undefined method `<' for nil:NilClass
Location /client_issue/create?client_id=15285
Action create
Controller client_issue
Query client_id=15285
Method POST
SSL true
如果有人输入诸如 2012 年 9 月 28 日之类的日期,则会发生异常。如果他们使用正确的三个字母月份(即 2012 年 9 月 28 日),则没有问题。事实上,任何无效的月份名称都会导致异常,例如 28 bjhg 2012。
这是堆栈跟踪的顶部
/shared/bundle/ruby/1.8/gems/timeliness-0.3.6/lib/timeliness/parser.rb:142:in `fast_date_valid_with_fallback'
/shared/bundle/ruby/1.8/gems/timeliness-0.3.6/lib/timeliness/parser.rb:24:in `make_time'
/shared/bundle/ruby/1.8/gems/timeliness-0.3.6/lib/timeliness/parser.rb:17:in `parse'
/shared/bundle/ruby/1.8/gems/validates_timeliness-3.0.14/lib/validates_timeliness/attribute_methods.rb:49:in `start_date='
/shared/bundle/ruby/1.8/gems/activerecord-3.2.8/lib/active_record/attribute_assignment.rb:85:in `send'
/shared/bundle/ruby/1.8/gems/activerecord-3.2.8/lib/active_record/attribute_assignment.rb:85:in `assign_attributes'
我的模型模型的相关位如下所示:
class ClientIssue < PauaServiceTable
validates_date :start_date ,:allow_blank => true
...
end
我的 gem 初始化程序包含以下内容:
config.restriction_shorthand_symbols.update(
:now => lambda { Time.current },
:today => lambda { Date.current }
)
config.parser.remove_formats(:date, 'm/d/yy')
config.parser.remove_us_formats
config.parser.use_euro_formats
我不明白为什么我会遇到异常。我应该能够通过任何旧垃圾并得到无效的日期消息,而不是例外。我有什么设置错误吗?