改变了?即使没有更改,方法也始终返回 TRUE 并包含 DateTime 字段(使用 jQuery UI datetimepicker)
我遇到了奇怪的问题 - 使用 jQuery UI datetimepicker 时(http://trentrichardson.com/examples/timepicker/) 对于编辑 DateTime 字段,Rails 似乎认为该字段总是会更改,即使我不更改它。问题是,如果该字段发生更改,我会进行验证并且它始终会被执行。
self.begin_time - self.changed_attributes["begin_time"] == 0.0 # => true
self.begin_time_changed? #=> true
我使用 text_field 来显示 DateTime 字段,并指定了时间格式和初始化程序,如下所示:
Time::DATE_FORMATS[:default] = "%d.%m.%Y %H:%M"
甚至更多:
@d.begin_time
# => Thu, 24 Nov 2011 14:00:00 MSK +04:00
@d.begin_time = "24.11.2011 14:00"
@d.begin_time_change
# => [Thu, 24 Nov 2011 14:00:00 MSK +04:00, Thu, 24 Nov 2011 14:00:00 MSK +04:00]
@d.begin_time_changed?
=> true
所以时间是相等的,我不知道如何进行更改?方法工作正常。
I have encountered strange problem - when using jQuery UI datetimepicker (http://trentrichardson.com/examples/timepicker/) for editing DateTime field it seems like Rails thinks that this field is always changed even if I don`t changed it. The thing is that I have validation if this field changed and it is always executed.
self.begin_time - self.changed_attributes["begin_time"] == 0.0 # => true
self.begin_time_changed? #=> true
I use text_field for displaying DateTime field and I specified Time format and initializer like this:
Time::DATE_FORMATS[:default] = "%d.%m.%Y %H:%M"
And even more:
@d.begin_time
# => Thu, 24 Nov 2011 14:00:00 MSK +04:00
@d.begin_time = "24.11.2011 14:00"
@d.begin_time_change
# => [Thu, 24 Nov 2011 14:00:00 MSK +04:00, Thu, 24 Nov 2011 14:00:00 MSK +04:00]
@d.begin_time_changed?
=> true
So times are equal and I don`t know how to make changed? method work properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论