From 2bbfaf0c9f6ad23cb2c64a917848ca180917ebe2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 23 Jul 2017 16:58:09 -0500 Subject: Demonstrate preloading in example --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index c1bfe12b77..8f340d7013 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,11 @@ class MessagesController < ApplicationController message.images.attach(params[:message][:images]) redirect_to message end + + def show + # Use the built-in with_attached_images scope to avoid N+1 + @message = Message.find(params[:id]).with_attached_images + end end ``` -- cgit v1.2.3