Skip to content

Conversation

adlamas
Copy link

@adlamas adlamas commented Oct 18, 2023

Discussion Link

Description:

@adlamas adlamas changed the title Enhancement/promote learning culture Promote a learning culture Oct 18, 2023
<li><%= comment.body %></li>
<% end %>
</ul>
<% end %>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this code, you have a N+1 problem. You can change it this way, WDYT?

Suggested change
<% end %>
# Fetch all posts and include comments
@posts = Post.includes(:comments).all
# In your view, you can display posts and comments without causing additional queries
<% @posts.each do |post| %>
<h2><%= post.title %></h2>
<ul>
<% post.comments.each do |comment| %>
<li><%= comment.body %></li>
<% end %>
</ul>
<% end %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant