ActiveRecord::StatementInvalid (PG::InvalidDatetimeFormat: ERROR: invalid input syntax for type date: ""

ActiveRecord::StatementInvalid (PG::InvalidDatetimeFormat: ERROR: invalid input syntax for type date: ""

在我的模型中,我有:

validates_presence_of :start_date, :message => 'Please enter date.'
validate :start_date_exist_check , on: :create`

def start_date_exist_check 
  @check_date = Employee.where('start_date = ?', start_date)`
  if @check_date.blank?
  end
end

validate_presence_of 在我的模块 start_date_exist_check 之后执行,这会产生问题。

谁能告诉我如何先验证该字段?

首先检查开始日期是否为空,如果为空,return从第一行开始

validates_presence_of :start_date, :message => 'Please enter date.'
validate :start_date_exist_check , on: :create`

def start_date_exist_check 
  return if start_date.blank?
  @check_date = Employee.where('start_date = ?', start_date)`
  if @check_date.blank?
  end
end

未测试 让我知道它是否不起作用