Commit 8bd5bba

Tyler Mercier <tylermercier@gmail.com>
2013-06-13 16:08:07
add forced n+1 example
1 parent ce6c8e0
Changed files (2)
app
config
app/controllers/cakes_controller.rb
@@ -2,7 +2,12 @@ class CakesController < ApplicationController
   before_filter :authenticate_user!, except: [:index, :show]
 
   def index
-    @cakes = Cake.all
+    @cakes = Cake.all(include: :category)
+  end
+
+  def n_plus_one
+    @cakes = Cake.all(include: :category)
+    render :index
   end
 
   def show
config/routes.rb
@@ -3,5 +3,8 @@ Confection::Application.routes.draw do
 
   resources :cakes
   resources :categories, :only => [:show], :path => 'c'
+
+  get 'n_plus_one', to: 'cakes#n_plus_one'
+
   root :to => 'cakes#index'
 end