如何使用ID别名Rails路线? [英] How do I alias a rails route with an id?
本文介绍了如何使用ID别名Rails路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下路线:
get '/welcome', to: redirect('/welcome/1')
get 'welcome/:id' => 'users#welcome'
重定向路由对/ welcome / 1执行301。
The redirect route does a 301 to /welcome/1.
我不想执行重定向,而是只执行ID为1的用户#welcome。
Instead of doing a redirect I'd like it to just execute users#welcome with an id of 1.
怎么办我这样做吗?
推荐答案
您需要:
get 'welcome', to: 'users#welcome', defaults: { id: 1 }
这篇关于如何使用ID别名Rails路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文