Ruby on rails 如何检测是否使用收集路由发出请求?
RubyonRails有一个特性,可以轻松地为资源创建收集路由。但是在控制器中,我们如何检测收集路由是否与当前请求匹配Ruby on rails 如何检测是否使用收集路由发出请求?,ruby-on-rails,ruby,routing,Ruby On Rails,Ruby,Routing,RubyonRails有一个特性,可以轻松地为资源创建收集路由。但是在控制器中,我们如何检测收集路由是否与当前请求匹配 resource :posts, :only => [:index, :show] do collection do get :archived, :action => :index end end 因此,在Posts#索引操作中,如何检查到索引操作的路径是否匹配?(索引或存档)应该有一种干净的方法来做到这一点。使用 耙道 并查看应用程序中的所有路
resource :posts, :only => [:index, :show] do
collection do
get :archived, :action => :index
end
end
因此,在Posts#索引操作中,如何检查到索引操作的路径是否匹配?(索引或存档)应该有一种干净的方法来做到这一点。使用
耙道
并查看应用程序中的所有路由。输出将是这样的
welcome_index GET /welcome/index(.:format) welcome#index
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root / welcome#index
你应该经历这件事 您是否在询问是否有多个路由指向一个操作,您是否可以在运行时确定哪个路由匹配?我想在运行时确定哪个路由真正匹配?你会对我的答案投反对票,而我的答案与我完全无关,因为你对我感到不安,所以你没有问自己这些问题?“当前路径”==“posts/index”。这不是我问的问题。你为什么不看看你的服务器日志,。。。。当你请求一个页面时,它就像“开始获取/some/something”。