The RouteSet
contains a collection of Route instances, representing the routes typically defined in config/routes.rb
.
命名空间
- 模块 ActionDispatch::Routing::RouteSet::MountedHelpers
- 类 ActionDispatch::Routing::RouteSet::CustomUrlHelper
- 类 ActionDispatch::Routing::RouteSet::Dispatcher
- 类 ActionDispatch::Routing::RouteSet::Generator
- 类 ActionDispatch::Routing::RouteSet::NamedRouteCollection
- 类 ActionDispatch::Routing::RouteSet::StaticDispatcher
方法
实例公共方法
from_requirements(requirements) 链接
返回与给定要求匹配的 Route,如果未找到,则返回 nil
。
这适用于语言服务器等工具。
假设路由定义如下
resources :posts
那么以下代码将返回 show
操作的 Route
Rails.application
.routes.from_requirements(controller: “posts”, action: “show”)
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/routing/route_set.rb, line 29 def from_requirements(requirements) routes.find { |route| route.requirements == requirements } end