You need to create a button which links to a controller action, and create a route for it like resend_email_path(user)
. Inside the controller action you need to include:
def resend_email
user = User.find(params[:id])
user.send_confirmation_instructions
end
For more information on this method see:
https://github.com/plataformatec/devise/blob/9f37b6eff7b4f9b0441be5a687b3091db82befc4/lib/devise/models/confirmable.rb#L110-L117
Once you get it working normally you could do it ajaxy with remote: true
To add the flash message, put this in in the controller action where your uncomfirmed user is:
if current_user.confirmation_period_expired?
flash[:error] = "Confirmation Time Expired. #{link_to 'Resend email', resend_email_path(user)}".html_safe
end
See: https://github.com/plataformatec/devise/blob/9f37b6eff7b4f9b0441be5a687b3091db82befc4/lib/devise/models/confirmable.rb#L218-L220