123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Routing::Mapper

Relationships & Source Files
Namespace Children
Modules:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: actionpack/lib/action_dispatch/routing/mapper.rb

Constant Summary

Resources - Included

CANONICAL_ACTIONS, RESOURCE_OPTIONS, VALID_ON_OPTIONS

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

CustomUrls - Included

#direct

Define custom URL helpers that will be added to the application’s routes.

#resolve

Define custom polymorphic mappings of models to URLs.

Resources - Included

#collection

To add a route to the collection:

#draw

Loads another routes file with the given name located inside the config/routes directory.

#match

Matches a URL pattern to one or more routes.

#member

To add a member route, add a member block into the resource block:

#namespace
#nested, #new,
#resource

Sometimes, you have a resource that clients always look up without referencing an ID.

#resources

In Rails, a resourceful route provides a mapping between HTTP verbs and URLs and controller actions.

#resources_path_names,
#root

You can specify what ::Rails should route “/” to with the root method:

#set_member_mappings_for_resource, #with_scope_level

Concerns - Included

#concern

Define a routing concern using a name.

#concerns

Use the named concerns.

Scoping - Included

#constraints

Parameter Restriction Allows you to constrain the nested routes based on a set of rules.

#controller

Scopes routes to a specific controller.

#defaults

Allows you to set default parameters for a route, such as this:

#namespace

Scopes routes to a specific namespace.

#scope

Scopes a set of routes to the given default options.

Redirection - Included

#redirect

Redirect any path to another path:

HttpHelpers - Included

#connect

Define a route that recognizes HTTP CONNECT (and GET) requests.

#delete

Define a route that only recognizes HTTP DELETE.

#get

Define a route that only recognizes HTTP GET.

#options

Define a route that only recognizes HTTP OPTIONS.

#patch

Define a route that only recognizes HTTP PATCH.

#post

Define a route that only recognizes HTTP POST.

#put

Define a route that only recognizes HTTP PUT.

Base - Included

#has_named_route?

Query if the following named route was already defined.

#match

Matches a URL pattern to one or more routes.

#mount

Mount a Rack-based application to be used within the application.

#with_default_scope

Class Attribute Details

.backtrace_cleaner (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 27

cattr_accessor :backtrace_cleaner, instance_accessor: false, default: BacktraceCleaner.new

.route_source_locations (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 26

cattr_accessor :route_source_locations, instance_accessor: false, default: false

Class Method Details

.normalize_name(name)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 412

def self.normalize_name(name)
  normalize_path(name)[1..-1].tr("/", "_")
end

.normalize_path(path)

Invokes Journey::Router::Utils.normalize_path, then ensures that /(:locale) becomes (/:locale). Except for root cases, where the former is the correct one.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 397

def self.normalize_path(path)
  path = Journey::Router::Utils.normalize_path(path)

  # the path for a root URL at this point can be something like
  # "/(/:locale)(/:platform)/(:browser)", and we would want
  # "/(:locale)(/:platform)(/:browser)" reverse "/(", "/((" etc to "(/", "((/" etc
  path.gsub!(%r{/(\(+)/?}, '\1/')
  # if a path is all optional segments, change the leading "(/" back to "/(" so it
  # evaluates to "/" when interpreted with no options. Unless, however, at least
  # one secondary segment consists of a static part, ex.
  # "(/:locale)(/pages/:page)"
  path.sub!(%r{^(\(+)/}, '/\1') if %r{^(\([^)]\))(\(/:[^)]\))*$}.match?(path)
  path
end