diff options
author | eileencodes <eileencodes@gmail.com> | 2015-08-22 09:44:12 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2015-08-22 09:44:24 -0400 |
commit | 4276b214f8a13a38ac7dc4911e90d295a8e40d5a (patch) | |
tree | 3711ad9a0fc8a3aa25372ec5d806812cc60a9447 /actionpack/lib/action_dispatch/http | |
parent | 0885a5cbf0c26fb01f95293b564267c70317ac9e (diff) | |
download | rails-4276b214f8a13a38ac7dc4911e90d295a8e40d5a.tar.gz rails-4276b214f8a13a38ac7dc4911e90d295a8e40d5a.tar.bz2 rails-4276b214f8a13a38ac7dc4911e90d295a8e40d5a.zip |
Refactor to remove controller class from route to request
This refactoring moves the controller class name that was on the route
set to the request. The purpose of this refactoring is for changes we
need to move controller tests to integration tests, mainly being able to
access the controller on the request instead of having to go through
the router.
[Eileen M. Uchitelle & Aaron Patterson]
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r-- | actionpack/lib/action_dispatch/http/request.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 1f480eec73..1189111f20 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -67,6 +67,18 @@ module ActionDispatch end end + def controller_class + check_path_parameters! + params = path_parameters + controller_param = params[:controller].underscore if params.key?(:controller) + params[:action] ||= 'index' + + yield unless controller_param + + const_name = "#{controller_param.camelize}Controller" + ActiveSupport::Dependencies.constantize(const_name) + end + def key?(key) @env.key?(key) end |