I'm trying to seed my rails api, I've migrated the scaffolds and I can create the entries on my localhost. I've also tried changing it to Person, and Car for each model but that doesn't work either.
my seed.rb:
People.create![
{firstname: 'Josh', lastname: 'Brolin', email: '[email protected]'},
{firstname: 'Emily', lastname: 'Blunt', email: '[email protected]'},
{firstname: 'Benicio', lastname: 'Del-Toro', email: '[email protected]'}
]
Cars.create![
{year: '2019', make: 'Audi', model: 'R8', price: '167000', person_id: '1'},
{year: '2010', make: 'Toyota', model: 'Camry', price: '6500', person_id: '2'},
{year: '2009', make: 'Honda', model: 'Civic', price: '4500', person_id: '3'},
{year: '2017', make: 'BMW', model: 'X5', price: '15000', person_id: '2'}
]
I'm getting this error when I run rails db:seed
:
NameError: uninitialized constant People
/home/pat/Desktop/test/carpeopleback/db/seeds.rb:9:in `<main>'
Tasks: TOP => db:seed
I've tried changing it to Person, and Car for each model but that doesn't work either. I've also tried running rails db:setup
with the same results
Not sure what I'm doing wrong. Thanks!
edit: this is my schema:
ActiveRecord::Schema[7.0].define(version: 2022_03_11_224419) do
create_table "cars", force: :cascade do |t|
t.integer "year"
t.string "make"
t.string "model"
t.integer "price"
t.integer "person_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "people", force: :cascade do |t|
t.string "firstname"
t.string "lastname"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
CodePudding user response:
People = [ {firstname: 'Josh', lastname: 'Brolin', email: '[email protected]'}, {firstname: 'Emily', lastname: 'Blunt', email: '[email protected]'}, {firstname: 'Benicio', lastname: 'Del-Toro', email: '[email protected]'} ]
People.each do |p|
Person.create! p
end
Check you model name as well it should be Person