Permalink
Browse files

AS guide: changes the example in explanation of MissingSourceFile

  • Loading branch information...
1 parent 8d32c2c commit 47a3701df9b9fbe456c5ede83333320f9456e7f5 @fxn fxn committed Aug 8, 2009
Showing with 8 additions and 9 deletions.
  1. +8 −9 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:
<ruby>
-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
</ruby>

0 comments on commit 47a3701

Please sign in to comment.