Nested Forms Tutorial: How do you display the Tasks in the Project Index and Show Views?
I am trying to display the Tasks on the Products#index and get Type Error in Projects#index
"can't cast Enumerator"
How can I display attributes from tasks on the Products views?
Here's my code -
ProjectsController:
def index
@projects = Project.all
@projects_id = @projects.find(:project_id)
@tasks = Project.where(:project_id => @projects_id).all
end
Projects#index:
<% @tasks.each do |task| %>
<%= task.description %>
<% end %>
AddIndexToTask migration:
def change
add_index :tasks, :project_id
end
I got it working.
def index
@projects = Project.all
end
Projects#index:
<% project.tasks.each do |task| %>
<%= task.description %>
<% end %>