Hi guys, the actual question is the following is not possible to bring the related rows from another table, there are two models Project and Todo two tables, respectively projects and todos, describe the models:
class Project < ApplicationRecord has_many :todos end and second
class Todo < ApplicationRecord belongs_to :project end the task to display a list of projects and tasks assigned to them, in the controller I write the following
class ProjectsController < ApplicationController def index @projects = Project.all @todos = Project.joins(:todos) end end then I write in the view
<% @projects.each do |pr| %> <h2><%= pr.title %></h2> <% @todos.each do |to| %> <h4><%= to.todo %></h4> <% end %> <% end %> and get
Ok, he suggests that I specify the todos method to to where, in theory, I keep associations for projects, but why todos? if this is the name of the table and not the todo attribute, ie the name of the column where I have the tasks in the todos table, because it works for the project.title? and yes if I do todos as he asks then I get this
please tell me what I do not understand? what am i doing wrong?
