Rails 修改请求路由
幸运的是,我正在创建一个 Rails 应用程序 (2.3.8),在其中我需要根据某些条件更改请求的分派位置。基本上,我需要一个自定义调度程序。
我研究过使用 Rack 来修改请求,并在某些情况下,将请求重新路由到知道与请求有关的不同控制器。
我不想重定向 - 我需要由与路由表给我的控制器不同的控制器处理一些请求。
这可能吗?
As luck would have it, I am creating a Rails application (2.3.8) in which I need to change where a request is dispatched based on some criteria. Basically, I need a custom dispatcher.
I have looked at using Rack to modify the request, and in certain instances, re-route the request to a different controller that knows that to do with the request.
I'm not looking to redirect - I need to have some requests handled by a different controller than the one the routing table gives me.
Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 Rack 就是这个问题的答案。您应该能够在请求到达 Rails 堆栈之前拦截请求并更改传入参数。
为什么不首先改变路线以使用正确的控制器呢?
I think Rack is the answer to this. You should be able to intercept the request and alter the incoming parameters before the request hits your Rails stack.
Why not change the route to use the correct controller in the first place?