为什么设计要生成这种格式的确认URL



设计保持生成这种格式的confirmation URL

http://something.com/users/confirmation/divyanshu-rawat?confirmation_token=CV3zV1wAWsb3RokHHEKN

我不知道为什么它没有产生这样的东西。

http://something.com/users/confirmation?confirmation_token=CV3zV1wAWsb3RokHHEKN

这就是我的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_confirmation_url(@resource, :confirmation_token => @resource.confirmation_token)

Devisegem中,确认路线创建如下,

#  # 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"}

因此,如果你想创建类似的url

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)`

同时检查路线.rb

如果您想在确认url中传递@resourceuser_namenamedb属性(正如您在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)

这将产生类似url,

http://something.com/users/confirmation/divyanshu-rawat?confirmation_token=CV3zV1wAWsb3RokHHEKN

最新更新