diff options
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-x | actionpack/lib/action_controller/base.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/url_rewriter.rb | 18 |
2 files changed, 17 insertions, 5 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index a7271e9c91..8bcf12a1a9 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -271,10 +271,11 @@ module ActionController #:nodoc: # .---> controller .--> action # /library/books/ISBN/0743536703/show # '------> '--------------> action_prefix - # controller_prefix + # controller_prefix (or module) # # * <tt>:controller_prefix</tt> - specifies the string before the controller name, which would be "/library" for the example. # Called with "/shop" gives "/shop/books/ISBN/0743536703/show". + # * <tt>:module</tt> - serves as a alias to :controller_prefix (overwrites :controller_prefix unless its nil) # * <tt>:controller</tt> - specifies a new controller and clears out everything after the controller name (including the action, # the pre- and suffix, and all params), so called with "settings" gives "/library/settings/". # * <tt>:action_prefix</tt> - specifies the string between the controller name and the action name, which would @@ -297,6 +298,7 @@ module ActionController #:nodoc: # Naturally, you can combine multiple options in a single redirect. Examples: # # redirect_to(:controller_prefix => "/shop", :controller => "settings") + # redirect_to(:controller_prefix => false, :controller => "settings") # breaks out of the current controller_prefix # redirect_to(:action => "edit", :id => 3425) # redirect_to(:action => "edit", :path_params => { "type" => "XTC" }, :params => { "temp" => 1}) # redirect_to(:action => "publish", :action_prefix => "/published", :anchor => "x14") diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 78638da39e..493e4911c6 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -12,7 +12,7 @@ module ActionController validate_options(VALID_OPTIONS, options.keys) rewrite_url( - rewrite_path(@rewritten_path, options), + rewrite_path(@rewritten_path, resolve_aliases(options)), options ) end @@ -30,8 +30,13 @@ module ActionController unknown_option_keys = supplied_option_keys - valid_option_keys raise(ActionController::ActionControllerError, "Unknown options: #{unknown_option_keys}") unless unknown_option_keys.empty? end + + def resolve_aliases(options) + options[:controller_prefix] = options[:module] unless options[:module].nil? + options + end - def rewrite_url(path, options) + def rewrite_url(path, options) rewritten_url = "" rewritten_url << @request.protocol unless options[:only_path] rewritten_url << @request.host_with_port unless options[:only_path] @@ -122,9 +127,14 @@ module ActionController end def controller_name(options, controller_prefix) - options[:controller_prefix] = "#{options[:module]}/#{options[:controller_prefix]}" if options[:module] ensure_slash_suffix(options, :controller_prefix) - controller_name = options[:controller_prefix] || controller_prefix || "" + + controller_name = case options[:controller_prefix] + when String: options[:controller_prefix] + when false : "" + when nil : controller_prefix || "" + end + controller_name << (options[:controller] + "/") if options[:controller] return controller_name end |