我通过以下迁移创建了AcademicInfo模型。它有一列称为备注,该字段是文本字段。基本上,我这样做是为了存储某种长文本。但是当我尝试用文本创建对象时,它给了我一种奇怪的“不是数字错误”
class CreateAcademicInfos < ActiveRecord::Migration[5.2]
def change
create_table :academic_infos do |t|
t.string :institution_name, null: false, default: ''
t.string :degree, null: false, default: ''
t.string :authority_body, null: false, default: ''
t.text :description_of_course, null: false, default: ''
t.date :start_date
t.date :end_date
t.text :remarks, null: false, default: ''
t.references :user, foreign_key: true
t.timestamps
end
end
end
我对控制器的请求消息是
{"institution_name": "Tribhuvan Uni", "authority_body": "Nepal Gov", "description_of_course": "Lamda Lamda description", "remarks": "THis is remarks", "start_date": "2018-12-12", "end_date": "2019-12-12", "degree": "Computer Sci", "user_id": 1}
但是我得到了错误
{
"remarks": [
"is not a number"
]
}
在我的模型中,我进行了以下验证
class AcademicInfo < ApplicationRecord
validates :institution_name, :presence => true, :length => {:minimum => 3, :maximum => 100}
validates :degree, :presence => true, :length => {:minimum => 3, :maximum => 100}
validates :authority_body, :presence => true, :length => {:minimum => 3, :maximum => 100}
validates :description_of_course, :presence => true, :length => {:minimum => 3, :maximum => 100}
validates :remarks, :numericality => true, :presence => true, :length => {:minimum => 3, :maximum => 100}
validates :remarks, :length => {:minimum => 5}, :allow_blank => true
validates :start_date, :presence => true
validates :end_date, :presence => true
belongs_to :user
end
无法弄清为什么会这样。
答案 0 :(得分:0)
对不起,输入数字是错误的:那边是真的