Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing the confirmation_url in Devise

How do you customize this default line generated by Devise in the mailer view?

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

I've written a method in my controller called user_confirm. And I have also defined a route for it. Can I get the URL to link to that method with token as the params?

like image 283
Shreyas Avatar asked Oct 21 '10 10:10

Shreyas


3 Answers

I used this routing:

map.user_confirm 'confirm/:confirmation_token',
    :controller => 'confirmations', :action => 'show'

And this ERB:

<%= link_to 'Confirm my account',
    user_confirm_url(:confirmation_token => @resource.confirmation_token) %>

And got this nice link:

http://localhost:3000/confirm/RjOnrd5yNREEDwsEfiFa
like image 77
Paul Schreiber Avatar answered Nov 20 '22 08:11

Paul Schreiber


Its something like (in routes.rb):

devise_scope :user do
  match '/confirm/:confirmation_token', :to => "devise/confirmations#show", :as => "user_confirm", :only_path => false
end

and in views you can use something like:

<%= link_to 'Confirm my account', user_confirm_url(@resource.confirmation_token) %>

for Rails 3.

like image 32
rkj Avatar answered Nov 20 '22 06:11

rkj


  • rails 4.0.5
  • devise 3.2.4

before

url:

http://example.com/users/confirmation?confirmation_token=jevYKv1z9Pr1LsAUB2NX

app/views/devise/mailer/confirmation_instructions.html.erb:

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

after

config/routes.rb:

devise_scope :user do
    get 'confirm/:confirmation_token', to: 'devise/confirmations#show'
end

app/views/devise/mailer/confirmation_instructions.html.erb:

<p><%= link_to 'Confirm my acount', confirm_url(@token) %></p>

url:

http://example.com/confirm/Kezap1iutgvXyQAhyu64
like image 4
user664833 Avatar answered Nov 20 '22 07:11

user664833