对不起,我在这里束手无策。
我有这个
validates :departing_at, :format => {
# 2012-07-14 10:00 am
:with => /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}) ([ap]m)$/,
:message => "must be date and time"
}
但它只是不会验证 2012-07-14 10:00 am 或与该正则表达式匹配的任何其他日期格式。
但是如果我把它放在控制器里面
pattern = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}) ([ap]m)$/
if params[:vacation][:departing_at] =~ pattern
raise "works"
else
raise params[:vacation][:departing_at].to_yaml
raise "doesn't work"
end
它打印出“作品”,伙计们有什么想法吗?:(