diff options
author | Xavier Noria <fxn@hashref.com> | 2009-08-08 02:54:48 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2009-08-08 02:54:48 +0200 |
commit | 47a3701df9b9fbe456c5ede83333320f9456e7f5 (patch) | |
tree | 486b5ec8ac617dd4576d2fc316e6d02d148ecc11 /railties | |
parent | 8d32c2c39b0a1968ff8d0998ecc6f145b53d1c0e (diff) | |
download | rails-47a3701df9b9fbe456c5ede83333320f9456e7f5.tar.gz rails-47a3701df9b9fbe456c5ede83333320f9456e7f5.tar.bz2 rails-47a3701df9b9fbe456c5ede83333320f9456e7f5.zip |
AS guide: changes the example in explanation of MissingSourceFile
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/active_support_overview.textile | 17 |
1 files 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: <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> |