From dd287205f5861f8bfbb744620010243d7054de50 Mon Sep 17 00:00:00 2001 From: Jeremy Mickelson Date: Mon, 2 Mar 2015 09:07:10 -0700 Subject: [PATCH] Don't crash with inherited models in subdirectories. (Check for file existance before requiring) --- lib/annotate/annotate_models.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index 709b5f95f..145a43806 100755 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -386,7 +386,8 @@ def get_model_class(file) get_loaded_model(model_path) or raise LoadError.new("cannot load a model from #{file}") rescue LoadError # this is for non-rails projects, which don't get Rails auto-require magic - if Kernel.require(file) + file_path = File.expand_path(file) + if File.file?(file_path) && Kernel.require(file_path) retry elsif model_path.match(/\//) model_path = model_path.split('/')[1..-1].join('/').to_s