非资源嵌套的命名路由 [英] Named route for non resource nesting
本文介绍了非资源嵌套的命名路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试生成一个链接,供用户单击以确认其帐户.我想要这个:
I'm trying to generate a link for a user to click to confirm their account. I'm wanting this:
/users/:id/confirm/:code
我已经在我的路线文件中找到了它:
I've got this in my routes file:
resources :users do
member do
get 'confirm/:confirmation_code', :action => 'confirm'
end
end
我尝试过:
user_confirm_path(@user, @confirmation_code)
confirm_user_path(@confirmation_code, @user)
和其他许多选项,但似乎找不到正确的选项.我想我总是可以自己生成链接网址,但是这似乎并不合理.
and many others but can't seem to get the right one. I guess I could always generate the link url myself but that doesn't seem the rails way.
这是我的耙子路由输出的内容:
This is what my rake routes outputs:
rake routes
Prefix Verb URI Pattern Controller#Action
GET /users/:id/confirm/:confirmation_code(.:format) users#confirm
但忽略了我实际上正在寻找的东西
but omits the thing I'm actually looking for
推荐答案
I had another similar question which was answered over here: Named routes inserting a . instead of a /
使用相同的答案解决此问题.
Using that same answer for this problem solved it.
这篇关于非资源嵌套的命名路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文