Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove HTTPS from Devise confirmation link when using Rack::SSLEnforcer

I'm using Devise and Rack::SSLEnforcer in a Rails app. When users receive their confirmation email, it looks something like:

http://mysite.com:443/users/confirmation?confirmation_token=123456789xxx

The link is auto-generated by Devise's confirmation_url method.

This link shouldn't have the port 443 attached to it. In theory, I don't need the link to be to the https address, but it's fine if it is. At minimum, it should be https at the front, not port 443 at the end.

Any ideas?

like image 851
ideaoforder Avatar asked Jun 23 '26 08:06

ideaoforder


1 Answers

I solved this problem by installing the Devise views and customizing the link being generated. You can install the Devise views with this command:

rails generate devise:views

Make sure to read the Devise documentation because you may need to customize some other stuff when you do this (depending on your particular situation).

With that complete, you can now edit the file at

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

To make the link always generate as SSL, just customize the link_to call:

<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :protocol => "https") %>
like image 172
wgrrrr Avatar answered Jun 25 '26 21:06

wgrrrr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!