在 Rails 中,您如何更改资源路由 url 但保持相同的 url 辅助方法?
In Rails how do you change a resources routes url but keep the same url helper methods?
我的路由文件中有一个简单的资源路由,如下所示:
resources :posts
我想把所有用这个的url改成articles
,比如/posts/1/edit
变成/articles/1/edit
现在这就像将 resources :posts
更改为 resources :articles
一样简单。
但是我想做的是将我代码中的所有帖子 url 保留到辅助方法 posts_url
输出新的 url /articles
我试过如下几种变体:
resources :posts, to: 'articles', as: 'posts'
但这似乎不起作用。非常感谢任何帮助。
中说明了
resources :posts, path: 'articles'
我的路由文件中有一个简单的资源路由,如下所示:
resources :posts
我想把所有用这个的url改成articles
,比如/posts/1/edit
变成/articles/1/edit
现在这就像将 resources :posts
更改为 resources :articles
一样简单。
但是我想做的是将我代码中的所有帖子 url 保留到辅助方法 posts_url
输出新的 url /articles
我试过如下几种变体:
resources :posts, to: 'articles', as: 'posts'
但这似乎不起作用。非常感谢任何帮助。
resources :posts, path: 'articles'