Rails——仅重新路由其中一条资源路由
我有一个名为 Entries 的资源,它具有与资源一起使用的所有正常默认 RESTful 路由。我想保留所有路由,除了我希望将 show
操作重新路由到我的文章控制器 (Articles#show
)。这是我的路线文件中当前(但不起作用)的代码:
resources :entries do
member do
get 'entry' => 'articles#show'
end
end
关于如何解决此问题的任何想法?我想将条目资源中的所有其他路线保留原样。
I have a resource called Entries, which has all the normal default RESTful routes that go along with a resource. I want to leave all the routes as they are EXCEPT I want the show
action to be rerouted to my Articles controller (Articles#show
). Here is my current (but not working) code in my routes file:
resources :entries do
member do
get 'entry' => 'articles#show'
end
end
Any ideas on how to solve this problem? I want to leave all the other routes from the Entries resource exactly as they are.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该在资源文章之前添加一个匹配项。
如果我理解的话,你想要路由 /entries/1/entry 去文章展示吗?
否则只需将匹配线更改为您想要的即可。
I think you should add a match before the resource articles.
If I understand, you want the route /entries/1/entry to go to the articles show?
Else just change the match line with what you want.