Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Last active August 22, 2016 02:56
Show Gist options
  • Save kinopyo/f72c1f02385d720073c118055d80f805 to your computer and use it in GitHub Desktop.
Save kinopyo/f72c1f02385d720073c118055d80f805 to your computer and use it in GitHub Desktop.
class Recipe < ApplicationRecord
belongs_to :user
end
class User < ApplicationRecord
end
class RecipesController < ApplicationController
def index
@recipes = Recipe.page(params[:page])
end
end
<% # recipes/index.html.erb %>
<ul>
<%= render @recipes %>
</ul>
<% # recipes/_recipe.html.erb %>
<li>
Title: <%= recipe.title %>
Author: <%= recipe.user.name %> <!-- here's the N+1 query -->
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment