123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Routing::Mapper

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

Constant Summary

Scoping - Included

POISON

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:

#action_options?, #action_path, #add_route, #applicable_actions_for, #apply_action_options, #apply_common_behavior_for, #canonical_action?, #decomposed_match, #get_to_from_path, #map_match, #match_root_route, #name_for_action, #nested_options, #param_constraint, #parent_resource, #path_for_action, #path_scope, #prefix_name_for_action, #resource_scope, #scope_action_options, #set_member_mappings_for_resource, #shallow_nesting_depth, #shallow_scope, #using_match_shorthand?, #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.

#merge_action_scope, #merge_as_scope, #merge_blocks_scope, #merge_constraints_scope, #merge_controller_scope, #merge_defaults_scope, #merge_format_scope, #merge_module_scope, #merge_options_scope, #merge_path_names_scope, #merge_path_scope, #merge_shallow_path_scope, #merge_shallow_prefix_scope, #merge_shallow_scope, #merge_to_scope, #merge_via_scope

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.

#map_method

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, #app_name, #define_generate_prefix, #rails_app?

Constructor Details

.new(set) ⇒ Mapper

This method is for internal use only.
[ GitHub ]

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

def initialize(set) # :nodoc:
  @set = set
  @draw_paths = set.draw_paths
  @scope = Scope.new(path_names: @set.resources_path_names)
  @concerns = {}
end

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