【问题标题】:rails 3 + devise: how do I make the email confirmation links use secure https (not http)rails 3 + devise:如何使电子邮件确认链接使用安全的 https(不是 http)
【发布时间】:2011-05-04 03:54:03
【问题描述】:

我如何告诉 Devise 使用 https(而不是 http)进行所有帐户确认和密码提醒等链接?

[注意:我不是在寻找将 all http 重定向到 https 的解决方案,我只需要设计以确保它创建的链接使用 https]

我们的 rails 3 应用程序使用 devise,该应用程序在 https 下运行良好,但是,devise 始终使用 http 作为电子邮件确认和通过电子邮件发送给用户的密码链接。

在我们的环境文件中我尝试更改:

config.action_mailer.default_url_options = { :host => "app1.mydomain.com" }  

 { :host => "https://app1.mydomain.com" }

但可以预见地设计创建的链接看起来像 http://https//app1.mydomain.com....(例如,它在 :host 设置前面加上 http:)

【问题讨论】:

    标签: ruby-on-rails https devise


    【解决方案1】:

    default_url_options 接受与url_for 相同的哈希参数。所以你应该能够做到这一点:

    config.action_mailer.default_url_options = { :protocol => 'https', :host => 'app1.mydomain.com' }
    

    【讨论】:

    • 如果您只需要特定链接,您可以在邮件模板中写入link_to "show", root_url(:protocol=>'https'),注意它应该是whatever_url 而不是whatever_path
    • 非常有帮助。这似乎是 ActionMailer 的普遍问题,不仅限于 Devise。将 ActionMailer::Base.default_url_options 设置为 {:protocol => 'https'} 即使您在应用程序中全局使用 force_ssl。
    【解决方案2】:

    要设置协议还要子目录:

    config.action_mailer.default_url_options = {
            :host => "www.example.com",
            :protocol => 'https',
            :only_path => false,
            :script_name => "/app" #add this attribute if your app is deployed in a subdirectory
        }
    

    Source

    【讨论】:

    • www 不包含在 url 中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 2016-02-28
    相关资源
    最近更新 更多