has_many, belongs_to relation in active record migration rails 4

前端 未结 6 1671
粉色の甜心
粉色の甜心 2020-12-12 15:28

I have a User model and a Task model. I have not mentioned any relation between them while creating them.

I need to establish that U

6条回答
  •  时光取名叫无心
    2020-12-12 16:05

    The migration will add the user's id to the task table so they know about each other

    rails g migration AddUserIdToTask user_id:integer
    

    then

    rake db:migrate
    

    And after update your controllers and views so that tasks can't be created on their own but must correspond to a user

提交回复
热议问题