module ActionDispatch::Routing::Mapper::CustomUrls

def direct(name, options = {}, &block)

+namespace+ or +scope+ and will raise an error if it detects that it is.
NOTE: The +direct+ method can't be used inside of a scope block such as

context in which you will use your custom URL helper when defining it.
then it will raise a +NameError+. Because of this you need to be aware of the

Rails.application.routes.url_helpers.browse_path

If the block is executed where there isn't a +params+ object such as this:
block is executed, e.g. generating a URL inside a controller action or a view.
In this instance the +params+ object comes from the context in which the

end
[ :products, options.merge(params.permit(:page, :size).to_h.symbolize_keys) ]
direct :browse, page: 1, size: 10 do |options|

your URL helper definition, e.g:
You can also specify default options that will be passed through to

your custom URL helper again otherwise it will result in a stack overflow error.
NOTE: Other URL helpers can be called in the block but be careful not to invoke

* An Active Model class
* An Active Model instance
* An array, which is passed to +polymorphic_url+
* A hash, e.g. { controller: "pages", action: "index" }
* A string, which is treated as a generated URL

be one of the following:
arguments for +url_for+ which will actually build the URL string. This can
The return value from the block passed to +direct+ must be a valid set of

end
{ controller: "pages", action: "index", subdomain: "www" }
direct :main do

end
[ model, anchor: model.dom_id ]
direct :commentable do |model|

end
"https://rubyonrails.org"
direct :homepage do

of routing helpers, e.g:
routes. This allows you to override and/or replace the default behavior
Define custom URL helpers that will be added to the application's
def direct(name, options = {}, &block)
  unless @scope.root?
    raise RuntimeError, "The direct method can't be used inside a routes scope block"
  end
  @set.add_url_helper(name, options, &block)
end