使用Rack :: SSLEnforcer时,从Devise确认链接中删除HTTPS [英] Remove HTTPS from Devise confirmation link when using Rack::SSLEnforcer

查看:94
本文介绍了使用Rack :: SSLEnforcer时,从Devise确认链接中删除HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails应用程序中使用Devise和Rack :: SSLEnforcer。当用户收到确认邮件时,看起来像:



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



该链接由Devise的confirm_url方法。



此链接不应将端口443附加到该链接。在理论上,我不需要链接到https地址,但是如果是这样的话。至少应该是https前端,而不是端口443。



任何想法?

解决方案

我通过安装Devise视图并自定义正在生成的链接来解决这个问题。您可以使用以下命令安装Devise视图:

  rails generate devise:views 

确保阅读Devise文档,因为您可能需要自定义其他内容(根据具体情况)。



完成之后,您可以在

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

使链接始终以SSL生成,只需自定义 link_to call:

 <%= link_to'确认我的帐户',confirm_url(@resource,:confirmation_token => @ resource.confirmation_token,:protocol =>https)%> 


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?

解决方案

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

这篇关于使用Rack :: SSLEnforcer时,从Devise确认链接中删除HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆