Last active
August 22, 2016 02:56
-
-
Save kinopyo/f72c1f02385d720073c118055d80f805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Recipe < ApplicationRecord | |
belongs_to :user | |
end | |
class User < ApplicationRecord | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RecipesController < ApplicationController | |
def index | |
@recipes = Recipe.page(params[:page]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% # 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