From 479e37856596625007b0d8db689983281634da79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Bu=C5=82at?= Date: Mon, 23 Feb 2015 15:57:39 +0100 Subject: [PATCH] Optimize Database#setup_attachment_class method --- lib/paperclip/storage/database.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/paperclip/storage/database.rb b/lib/paperclip/storage/database.rb index 09613dc..b8fd6ee 100644 --- a/lib/paperclip/storage/database.rb +++ b/lib/paperclip/storage/database.rb @@ -108,10 +108,11 @@ def setup_paperclip_file_model def setup_attachment_class instance.class.ancestors.each do |ancestor| + next unless ancestor.respond_to?(:attachment_definitions) + # Pick the top-most definition like # Paperclip::AttachmentRegistry#definitions_for - names_for_ancestor = ancestor.attachment_definitions.keys rescue [] - if names_for_ancestor.member?(name) + if ancestor.attachment_definitions.member?(name) @attachment_class = ancestor end end