method
match
v8.1.1 -
Show latest stable
- Class:
ActionDispatch::Routing::Mapper::Mapping::Resources
match(*path_or_actions, as: DEFAULT, via: nil, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)public
Matches a URL pattern to one or more routes. For more information, see [match](rdoc-ref:Base#match).
match 'path', to: 'controller#action', via: :post match 'otherpath', on: :member, via: :get
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1837
def match(*path_or_actions, as: DEFAULT, via: nil, to: nil, controller: nil, action: nil, on: nil, defaults: nil, constraints: nil, anchor: nil, format: nil, path: nil, internal: nil, **mapping, &block)
if path_or_actions.grep(Hash).any? && (deprecated_options = path_or_actions.extract_options!)
as = assign_deprecated_option(deprecated_options, :as, :match) if deprecated_options.key?(:as)
via ||= assign_deprecated_option(deprecated_options, :via, :match)
to ||= assign_deprecated_option(deprecated_options, :to, :match)
controller ||= assign_deprecated_option(deprecated_options, :controller, :match)
action ||= assign_deprecated_option(deprecated_options, :action, :match)
on ||= assign_deprecated_option(deprecated_options, :on, :match)
defaults ||= assign_deprecated_option(deprecated_options, :defaults, :match)
constraints ||= assign_deprecated_option(deprecated_options, :constraints, :match)
anchor = assign_deprecated_option(deprecated_options, :anchor, :match) if deprecated_options.key?(:anchor)
format = assign_deprecated_option(deprecated_options, :format, :match) if deprecated_options.key?(:format)
path ||= assign_deprecated_option(deprecated_options, :path, :match)
internal ||= assign_deprecated_option(deprecated_options, :internal, :match)
assign_deprecated_options(deprecated_options, mapping, :match)
end
raise ArgumentError, "Wrong number of arguments (expect 1, got #{path_or_actions.count})" if path_or_actions.count > 1
if path_or_actions.none? && mapping.any?
hash_path, hash_to = mapping.find { |key, _| key.is_a?(String) }
if hash_path.nil?
raise ArgumentError, "Route path not specified"
else
mapping.delete(hash_path)
end
if hash_path
path_or_actions.push hash_path
case hash_to
when Symbol
action ||= hash_to
when String
if hash_to.include?("#")
to ||= hash_to
else
controller ||= hash_to
end
else
to ||= hash_to
end
end
end
path_or_actions.each do |path_or_action|
if defaults
defaults(defaults) { map_match(path_or_action, as,, via,, to,, controller,, action,, on,, constraints,, anchor,, format,, path,, internal,, mapping,, &block) }
else
map_match(path_or_action, as,, via,, to,, controller,, action,, on,, constraints,, anchor,, format,, path,, internal,, mapping,, &block)
end
end
end Related methods
- Instance methods
- collection
- draw
- match
- member
- namespace
- nested
- new
- resource
- resources
- resources_path_names
- root
- shallow
- shallow?
- Private methods
-
action_options? -
action_path -
add_route -
api_only? -
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 -
nested_scope? -
param_constraint -
param_constraint? -
parent_resource -
path_for_action -
path_scope -
prefix_name_for_action -
resource_method_scope? -
resource_scope -
resource_scope? -
scope_action_options -
set_member_mappings_for_resource -
shallow_nesting_depth -
shallow_scope -
using_match_shorthand? -
with_scope_level