diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-11 00:08:18 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-11 00:08:43 +0200 |
commit | a87894ae57dcabbb299886959ec5646e356a7b56 (patch) | |
tree | 594d1808788c0a093970a54a5fd96dd32d28877d /actionpack/lib | |
parent | 9a7dbe2c0570e11b9033df735c937d5f5416e0ca (diff) | |
download | rails-a87894ae57dcabbb299886959ec5646e356a7b56.tar.gz rails-a87894ae57dcabbb299886959ec5646e356a7b56.tar.bz2 rails-a87894ae57dcabbb299886959ec5646e356a7b56.zip |
Get around weird missing constant error caused by AS instead of simply raising NameError, closes #477.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 881af74147..9b27bb8b91 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -136,15 +136,23 @@ module ActionController # this could be done by trying to find the defined model that has the # same singularize name as the controller. For example, +UsersController+ # will try to find if the +User+ model exists. - def _default_wrap_model + # + # This method also does namespace lookup. Foo::Bar::UsersController will + # try to find Foo::Bar::User, Foo::User and finally User. + def _default_wrap_model #:nodoc: model_name = self.name.sub(/Controller$/, '').singularize begin model_klass = model_name.constantize - rescue NameError => e - unscoped_model_name = model_name.split("::", 2).last - break if unscoped_model_name == model_name - model_name = unscoped_model_name + rescue NameError, ArgumentError => e + if e.message =~ /is not missing constant|uninitialized constant #{model_name}/ + namespaces = model_name.split("::") + namespaces.delete_at(-2) + break if namespaces.last == model_name + model_name = namespaces.join("::") + else + raise + end end until model_klass model_klass |