aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-23 16:58:09 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-23 16:58:09 -0500
commit2bbfaf0c9f6ad23cb2c64a917848ca180917ebe2 (patch)
tree3ebc65daf6d6bfd904a455afc8008478a2b01d55
parente16d0c9ceacd771c99048385dc886c6026c7bc45 (diff)
downloadrails-2bbfaf0c9f6ad23cb2c64a917848ca180917ebe2.tar.gz
rails-2bbfaf0c9f6ad23cb2c64a917848ca180917ebe2.tar.bz2
rails-2bbfaf0c9f6ad23cb2c64a917848ca180917ebe2.zip
Demonstrate preloading in example
-rw-r--r--README.md5
1 files changed, 5 insertions, 0 deletions
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
```