method
match
v5.0.0.1 -
Show latest stable
- Class:
ActionDispatch::Routing::Mapper::Scoping::Resources
match(path, *rest)public
Matches a url pattern to one or more routes. For more information, see match[rdoc-ref:Base#match].
match 'path' => 'controller#action', via: patch match 'path', to: 'controller#action', via: :post match 'path', 'otherpath', on: :member, via: :get
# File actionpack/lib/action_dispatch/routing/mapper.rb, line 1569
def match(path, *rest)
if rest.empty? && Hash === path
options = path
path, to = options.find { |name, _value| name.is_a?(String) }
case to
when Symbol
options[:action] = to
when String
if to =~ /#/
options[:to] = to
else
options[:controller] = to
end
else
options[:to] = to
end
options.delete(path)
paths = [path]
else
options = rest.pop || {}
paths = [path] + rest
end
if options[:on] && !VALID_ON_OPTIONS.include?(options[:on])
raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
end
if @scope[:to]
options[:to] ||= @scope[:to]
end
if @scope[:controller] && @scope[:action]
options[:to] ||= "#{@scope[:controller]}##{@scope[:action]}"
end
controller = options.delete(:controller) || @scope[:controller]
option_path = options.delete :path
to = options.delete :to
via = Mapping.check_via Array(options.delete(:via) {
@scope[:via]
})
formatted = options.delete(:format) { @scope[:format] }
anchor = options.delete(:anchor) { true }
options_constraints = options.delete(:constraints) || {}
path_types = paths.group_by(&:class)
path_types.fetch(String, []).each do |_path|
route_options = options.dup
if _path && option_path
ActiveSupport::Deprecation.warn Specifying strings for both :path and the route path is deprecated. Change things like this: match #{_path.inspect}, :path => #{option_path.inspect}to this: match #{option_path.inspect}, :as => #{_path.inspect}, :action => #{path.inspect}
route_options[:action] = _path
route_options[:as] = _path
_path = option_path
end
to = get_to_from_path(_path, to, route_options[:action])
decomposed_match(_path, controller, route_options, _path, to, via, formatted, anchor, options_constraints)
end
path_types.fetch(Symbol, []).each do |action|
route_options = options.dup
decomposed_match(action, controller, route_options, option_path, to, via, formatted, anchor, options_constraints)
end
self
end Related methods
- Instance methods
- add_route
- collection
- decomposed_match
- get_to_from_path
- match
- member
- namespace
- nested
- new
- resource
- resources
- resources_path_names
- root
- shallow
- shallow?
- using_match_shorthand?
- Protected methods
-
action_options? -
action_path -
api_only? -
apply_action_options -
apply_common_behavior_for -
canonical_action? -
name_for_action -
nested_options -
nested_scope? -
param_constraint -
param_constraint? -
parent_resource -
path_for_action -
prefix_name_for_action -
resource_method_scope? -
resource_scope -
resource_scope? -
scope_action_options -
set_member_mappings_for_resource -
shallow_nesting_depth -
shallow_scope -
with_scope_level - Private methods
-
match_root_route -
path_scope