내 Rails 앱의 날짜/시간 필드에 문제가 있습니다. 내가 null 또는 빈 값 (코드 내 question 어제부터입니다) 유효 날짜 시간을 받아 들여야 검증을하고 있습니다 : 어떤 문자열로 datetime_field 설정할 때날짜/시간 필드는 문자열을 저장할 때 nil 값을 저장합니다.
include ActiveModel::Validations
class DateValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
record.errors[attribute] << "must be a valid datetime" unless ((DateTime.parse(value) rescue nil))
end
end
validates :datetime_field :date => true, :allow_nil => true, :allow_blank => true
을, 내 모델 datetime_field의 이전 값을 무시하고 레일 콘솔에서 나는 다음과 같은 수 (전무로 설정 : 내 날짜 필드를 설정 중지하는 방법
object.update_attributes("datetime_field" => "Now")
true
object.datetime_field.nil?
true
전무 문자열로 업데이트 함과 동시에이 분야를 명시 적으로 빈 할 수있는 유지 후
에?