在Devise gem 中,用于确认的路线如下创建,
# # Confirmation routes for Confirmable, if User model has :confirmable configured
# new_user_confirmation GET /users/confirmation/new(.:format) {controller:"devise/confirmations", action:"new"}
# user_confirmation GET /users/confirmation(.:format) {controller:"devise/confirmations", action:"show"}
# POST /users/confirmation(.:format) {controller:"devise/confirmations", action:"create"}
因此,如果您想创建类似的网址,
http://something.com/users/confirmation?confirmation_token=CV3zV1wAWsb3RokHHEKN
采用
user_confirmation_url(confirmation_token: @resource.confirmation_token)`
代替
user_confirmation_url(@resource, confirmation_token: @resource.confirmation_token)`
还要检查routes.rb
如果您想在确认 url 中传递user_name或name db 属性@resource
(正如您在 url 中传递 'divyanshu-rawat' 所要求的那样),您可以创建自己的自定义路由,该路由将指向相同的控制器和操作,如下所示,
# config/routes.rb
devise_for :users
as :user do
get '/users/confirmation/:name' => "devise/confirmations#show", as: 'user_confirm'
end
如果在你的情况下,@resource.user_name = 'divyanshu-rawat',更新confirmation_instructions.html.haml
如下,
%p Welcome #{@resource.first_name}!
%p You can confirm your account email through the link below:
%p= link_to 'Confirm my account', user_confirm_url(name: @resource.user_name, confirmation_token: @resource.confirmation_token)
这将产生像这样的网址,
http://something.com/users/confirmation/divyanshu-rawat?confirmation_token=CV3zV1wAWsb3RokHHEKN