diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 073dabd0a8..10d733e477 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -2034,7 +2034,7 @@ module ActionDispatch # end # # direct :main do - # { controller: 'pages', action: 'index', subdomain: 'www' } + # { controller: "pages", action: "index", subdomain: "www" } # end # # The return value from the block passed to `direct` must be a valid set of @@ -2042,7 +2042,7 @@ module ActionDispatch # be one of the following: # # * A string, which is treated as a generated url - # * A hash, e.g. { controller: 'pages', action: 'index' } + # * A hash, e.g. { controller: "pages", action: "index" } # * An array, which is passed to `polymorphic_url` # * An Active Model instance # * An Active Model class @@ -2057,6 +2057,15 @@ module ActionDispatch # [ :products, options.merge(params.permit(:page, :size)) ] # end # + # In this instance the `params` object comes from the context in which the the + # block is executed, e.g. generating a url inside a controller action or a view. + # If the block is executed where there isn't a params object such as this: + # + # Rails.application.routes.url_helpers.browse_path + # + # then it will raise a `NameError`. Because of this you need to be aware of the + # context in which you will use your custom url helper when defining it. + # # NOTE: The `direct` method can't be used inside of a scope block such as # `namespace` or `scope` and will raise an error if it detects that it is. def direct(name, options = {}, &block) @@ -2101,7 +2110,7 @@ module ActionDispatch # You can pass options to a polymorphic mapping - the arity for the block # needs to be two as the instance is passed as the first argument, e.g: # - # direct class: "Basket", anchor: "items" do |basket, options| + # resolve "Basket", anchor: "items" do |basket, options| # [:basket, options] # end # |