How can I use Devify `confirm_url` outside the mailer?

I am using Devise in a rails project. I want to pass the verification URL to third parties. This url is created by the expression confirmation_url(@resource, confirmation_token: @token)in the following View view:

https://github.com/plataformatec/devise/blob/master/app/views/devise/mailer/confirmation_instructions.html.erb

I have grepped all Devise source code trying to figure out who or where confirmation_url, but I couldn't find anything; it appears only on representations, so it must be dynamically generated by something.

In a regular Rails application, I can use Rails.application.routes.url_helpersto create URLs (e.g. Rails.application.routes.url_helpers.user_path(@user)).

Is there anything similar that I can use to call confirmation_urloutside maker views?

+4
source share
1 answer

Ok, so after fighting this for a while, I decided to read the explanation at the top of this file:

https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/url_helpers.rb

It turns out that Devise generates by default (at least in my application) - these are routes. confirmation_urlis an assistant, but you can still see the routes that Devise generates:

rake routes | grep confirm

Since I use a model called Accountinstead User, this gives me the following:

account_confirmation     POST /accounts/confirmation(.:format)  accounts/confirmations#create
new_account_confirmation GET  /accounts/confirmation/new(.:format) accounts/confirmations#new
                         GET  /accounts/confirmation(.:format)                         accounts/confirmations#show
confirm_account        PATCH  /accounts/confirmation(.:format)                         accounts/confirmations#update

, , :

http://myserver.com/accounts/confirm?confirmation_token=xxxx

- GET. - , POST ; account_confirmation. URL- rails URL-:

Rails.application
     .routes.url_helpers
     .account_confirmation_url(confirmation_token: account.confirmation_token)

URL-, . Account User Devise.

+5

All Articles