【发布时间】:2020-12-28 04:21:18
【问题描述】:
这是我的 ActiveRecord:
class CreateTasks < ActiveRecord::Migration[6.1]
def change
create_table :tasks do |t|
t.string :title
t.text :body
t.datetime :due
t.integer :priority
t.text :tag
t.timestamps
end
end
end
我试图在rails console 中创建一个对象并保存它,但它一直返回 false
irb(main):008:0> t =Task.new(title:"First task", body:"body of first task", due:"2020-12-29", priority:2, tag:"tag of first task")
=> #<Task id: nil, title: "First task", body: "body of first task", tag: "tag of first task", due: nil, priority: 2, created_at: nil, updated_at: nil>
irb(main):018:0> t.save
=> false
我检查了多个站点以确保我的语法正确,但我仍然无法保存此对象
我的任务模型
class Task < ApplicationRecord
belongs_to :container
validates :title, presence: true
validates :body, presence: true, length: { minimum: 10 }
validates :priority, presence: true
validates :due, presence: true
validates :tag, presence: true
end
【问题讨论】:
标签: sql ruby-on-rails database