Confirm confirm_url in the development program

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

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

I wrote a method in my controller called user_confirm. And I also determined the route for it. Can I get a url to link to this method with a token as parameters?

+3
source share
5 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
+7
source

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 the views you can use something like:

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

for Rails 3.

+7
source
  • rails 4.0.5
  • devise 3.2.4

URL:

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

////confirmation_instructions.html.erb:

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

/routes.rb:

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

////confirmation_instructions.html.erb:

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

URL:

http://example.com/confirm/Kezap1iutgvXyQAhyu64
+2

. , , .

map.user_confirm '/user_confirm',  :controller => 'users', :action => 'confirm'

, ,

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

URL- "confirm_at" , , :

1 after_confirmation_path_for :

confirmations_controller.rb /:

class ConfirmationsController < Devise::ConfirmationsController
  private
  def after_confirmation_path_for(resource_name, resource)
  your_new_after_confirmation_path
 end
end

STEP 2 In config / routes.rb add this line so that Devise will use your custom ConfirmationsController. This assumes that Devise works with the user table (you can edit it according to yours).

devise_for :users, controllers: { confirmations: 'confirmations' }

STEP 3 Restart the web server

0
source

All Articles