The variable var
is a boolean
and should not be allowed to be blank. Therefore in my model file I have:
validates_inclusion_of :var, :in => [true, false]
validates :var, presence: true
In my seeds file I have:
title = "abc"
var = [true, false].sample
author.articles.create!( title: title,
var: var)
Seeding produces the error:
ActiveRecord::RecordInvalid: Validation failed: Var can't be blank
Does anyone understand why it wants to create an article with a blank var?
Update: Using the debugger
, I can confirm that var had a value of 1.
Schema for articles:
create_table "articles", force: :cascade do |t|
t.integer "author_id"
t.string "title", limit: 50, null: false
t.boolean "var", default: true, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end