Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise confirmable, how to resend a confirmation email on click?

I'm using devise confirmable. I want to give the user a link to click and resend the confirmation email. Problem is, when the user clicks the link, it isn't going to the devise controller. Is there something I'm missing in the routes.rb file? Here is my setup:

routes.rb

devise_for :users, :controllers => { :registrations => "registrations", :sessions => "sessions", :omniauth_callbacks => "authentications" }

user.rb

devise :omniauthable, :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable

The view:

<a href="/users/confirmation/new" data-remote="true" data-method="post">Resend confirmation</a>

Thanks

like image 764
AnApprentice Avatar asked Mar 09 '12 01:03

AnApprentice


3 Answers

to send confirmation instructions to the user you find the user and then just user.send_confirmation_instructions

namespace :user do
  task :resend_confirmation => :environment do
    users = User.where('confirmation_token IS NOT NULL')
    users.each do |user|
      user.send_confirmation_instructions
    end
  end
end
like image 172
MZaragoza Avatar answered Nov 09 '22 05:11

MZaragoza


resource_params

is a method defined at devise controller which gets the controller resources specific do device resource (User) for example. definition in DeviseController

def resource_params
params.fetch(resource_name, {})
end

so in order to pass the email as a parameter you neet to include it in a user hash, so in the view instead of

link_to('resend', user_confirmation_path(email: "[email protected]"), :method => :post)                    

insert the email in a Hash

link_to('resend', user_confirmation_path(user: {:email => "[email protected]"}), :method => :post)

this way devise will pick up the email parameter

like image 11
bigsolom Avatar answered Nov 09 '22 07:11

bigsolom


Pretty old post. Though, instead of sending the instructions directly, you might just want to point the user to Devise's workflow:

= link_to 'Resend confirmation', new_user_confirmation_path

That'll take the user to Devise's view requesting the email to send the confirmation instructions.

Hope it helps anyone, anyway. :)

like image 8
Gabriel Osorio Avatar answered Nov 09 '22 07:11

Gabriel Osorio