Why does this create method make a nil
record?
I have tried:
Dropdown.create(subject: "test")
Dropdown.create({subject: "test", subject_value: "1"})
Dropdown.create({:subject => "test", :subject_value => "1"})
All result in nil
records.
(0.1ms) begin transaction
SQL (0.6ms) INSERT INTO "dropdowns" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-01-21 23:58:04.979225"], ["updated_at", "2016-01-21 23:58:04.979225"]]
(2.1ms) commit transaction
=> #<Dropdown id: 145, subject: nil, visible: nil, subject_value: nil, subject_description: nil, created_at: "2016-01-21 23:58:04", updated_at: "2016-01-21 23:58:04
Model file
class Dropdown < ActiveRecord::Base
FIELDS = [
:subject,
:visible,
:subject_value,
:subject_description
]
attr_accessor(*FIELDS)
subjects = %w[math english spanish]
subjects.each do |s|
scope s.to_sym, -> { where(subject: s) }
end
end
Migration file
class CreateDropdowns < ActiveRecord::Migration
def change
create_table :dropdowns do |t|
t.string :subject
t.boolean :visible
t.string :subject_value
t.string :subject_description
t.timestamps null: false
end
end
end