From 566a3dce6753eb71554d54e8883204e4868aa393 Mon Sep 17 00:00:00 2001 From: Mike Ferrier Date: Thu, 4 Dec 2008 13:31:18 -0600 Subject: [PATCH] Make NoMethodError message more descriptive when an undefined message has been sent to an association [#1515 state:resolved] Signed-off-by: Joshua Peek --- .../lib/active_record/associations/association_proxy.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 75ec4fbb2ec0a..59f1d3b867997 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -207,7 +207,10 @@ def with_scope(*args, &block) # Forwards any missing method call to the \target. def method_missing(method, *args) if load_target - raise NoMethodError unless @target.respond_to?(method) + unless @target.respond_to?(method) + message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" + raise NoMethodError, message + end if block_given? @target.send(method, *args) { |*block_args| yield(*block_args) }