From 47a3701df9b9fbe456c5ede83333320f9456e7f5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 8 Aug 2009 02:54:48 +0200 Subject: [PATCH] AS guide: changes the example in explanation of MissingSourceFile --- .../source/active_support_overview.textile | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile index f7234b3383..10e098b029 100644 --- a/railties/guides/source/active_support_overview.textile +++ b/railties/guides/source/active_support_overview.textile @@ -890,15 +890,14 @@ The class +MissingSourceFile+ is a subclass of +LoadError+, so any code that res For example, when an action of +PostsController+ is called Rails tries to load +posts_helper.rb+, but that file may not exist. That's fine, the helper module is not mandatory so Rails silences a load error. But it could be the case that the helper module does exist, but it in turn requires another library that is missing. In that case Rails must reraise the exception. The method +is_missing?+ provides a way to distinguish both cases: -def inherited_with_helper(child) - inherited_without_helper(child) - begin - child.master_helper_module = Module.new - child.master_helper_module.__send__(:include, master_helper_module) - child.helper child.name.to_s.underscore - rescue MissingSourceFile => e - raise unless e.is_missing?("#{child.name.to_s.underscore}_helper") - end +def default_helper_module! + module_name = name.sub(/Controller$/, '') + module_path = module_name.underscore + helper module_path +rescue MissingSourceFile => e + raise e unless e.is_missing? "#{module_path}_helper" +rescue NameError => e + raise e unless e.missing_name? "#{module_name}Helper" end