Answer the question
In order to leave comments, you need to log in
How to link two tables in Rails?
Hello! I have a problem, I immediately ask you not to scold me for being a teapot, and so. I have an application in ToDo, and I need to link the Project(id, name) table with the Task(id, name, status, project_id) table. So that in one project there are many tasks.
I need to create a task for the current project. How?
Answer the question
In order to leave comments, you need to log in
You need a has_many relationship. To do this, in the Project model you need to register:
# project.rb
has_many :tasks
# вызывать так
project = Project.first
project.tasks # список всех тасков у проекта
project.tasks.create({ ... }) # создание нового таска
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question