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

六眼飞鱼酱① 提交于 2020-01-15 01:55:27

问题


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?


回答1:


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") %>


来源:https://stackoverflow.com/questions/9038632/remove-https-from-devise-confirmation-link-when-using-racksslenforcer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!