Issue with loading rails seed data -
i trying load seed data rails application , giving 1 error don't understand. below seed.rb
file , terminal output above it.
thanks in advance
the error don't have singular todo_list
association in user
model, calling create_todo_list
won't work.
- when using
belongs_to
/has_one
, can callcreate_singular_association
- when using
has_many
, have callcollection.create
thus, you'll need following in db/seeds.rb
:
#27 todo = duser.todo_lists.create list_name: "list", list_due_date: date.today + 1.year #28 items = todo.todo_items.create todolistiems
--
this assuming have following models:
#app/models/user.rb class user < activerecord::base has_many :todo_lists has_many :todo_list_items, through: :todo_lists end #app/models/todo_list.rb class todolist < activerecord::base belongs_to :user has_many :todo_list_items end
Comments
Post a Comment