Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails:confirm_X_url生成http而不是https_Ruby On Rails_Apache - Fatal编程技术网

Ruby on rails Rails:confirm_X_url生成http而不是https

Ruby on rails Rails:confirm_X_url生成http而不是https,ruby-on-rails,apache,Ruby On Rails,Apache,我一直跟着。在那篇文章中,作者创建了注册确认.text.erb: Hi <%= @user.name %>, Thanks for registering! To confirm your registration click the URL below. <%= confirm_email_user_url(@user.confirm_token) %> 你好, 谢谢注册!要确认您的注册,请单击下面的URL。 作者没有解释如何创建确认\u电子邮件\u用户\u u

我一直跟着。在那篇文章中,作者创建了注册确认.text.erb

Hi <%= @user.name %>,

Thanks for registering! To confirm your registration click the URL below.

<%= confirm_email_user_url(@user.confirm_token) %>
你好,
谢谢注册!要确认您的注册,请单击下面的URL。
作者没有解释如何创建确认\u电子邮件\u用户\u url。我试图跟踪元编程代码,我相信最终创建输出字符串的是源模块lib/action\u dispatch/routing/route\u set.rb中的url\u

我的注册\u确认.text.erb

<%# See https://coderwall.com/p/u56rra/ruby-on-rails-user-signup-email-confirmation-tutorial %>

Hi <%= @email_address.email_address %>,

Thanks for registering! To confirm your registration click the URL below.

<%
  confirmation_url =
    confirm_email_email_address_url(
      @email_address.confirm_token
    )
  regex=/\A(http:\/\/)/
  confirmation_url.gsub!(regex, 'https://')
%>
<%= confirmation_url %>

你好
谢谢注册!要确认您的注册,请单击下面的URL。
如果我没有将输出字符串从http转换为https,则会出现以下错误:

找不到请求的URL /在上未找到电子邮件地址/v8HJgSaGGysoxIC-ghX8lw/确认电子邮件 这台服务器

Apache/2.4.18(Ubuntu)服务器,位于www.myWebsite.com端口 80 如果我强迫强者https://... 而不是http://... 然后一切正常,url被正确地路由到Rails

问题
  • 我如何告诉confirm_X_url(即confirm_email_user_url)到 生成https而不是http
  • 这可能不是一个问题; 我应该告诉Apache、Rails和其他(?)什么东西 http并自动将其转换为https?我跟着台阶走了进去 但它似乎不符合我的要求
  • 或者将此帮助程序放入app/controllers/application_controller.rb

    def default_url_options(options={})
     { :secure => true }
    end
    
    这会解决链接问题,让你马上跑起来,但这不是正确的做法。您可以使用以下一些.htaccess指令:

    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*) https://%{HTTP_HOST}/$1
    
    或者,这就是我要做的,注册像cloudflare这样的东西,在那里你可以为你的站点获得一系列的保护,如果你要求的话,它会强制重定向

    以下是该信息的链接:

    或者将此帮助程序放入app/controllers/application_controller.rb

    def default_url_options(options={})
     { :secure => true }
    end
    
    这会解决链接问题,让你马上跑起来,但这不是正确的做法。您可以使用以下一些.htaccess指令:

    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*) https://%{HTTP_HOST}/$1
    
    或者,这就是我要做的,注册像cloudflare这样的东西,在那里你可以为你的站点获得一系列的保护,如果你要求的话,它会强制重定向

    以下是该信息的链接:

    Do
    rake routes
    查看所有可能的路由,在那里还可以查看路由的名称。然后使用该名称构建方法
    \u path
    \u url

    如果使用相对的
    \u路径
    ,它将从当前url(包括
    https
    )开始,而不是使用
    \u url
    。但这在构建邮件时不起作用

    通过在
    config/environments/production.rb
    中设置标志
    config.Force\u ssl=true
    ,强制应用程序始终在生产模式下使用ssl

    此外,在邮件程序中执行此操作时,您可能需要设置以下内容:

    # production.rb
    config.action_mailer.default_url_options = {
      host: 'yourdomain.com',
      protocol: 'https'
    }
    

    执行
    rake routes
    查看所有可能的路由,在那里您还可以看到路由的名称。然后使用该名称构建方法
    \u path
    \u url

    如果使用相对的
    \u路径
    ,它将从当前url(包括
    https
    )开始,而不是使用
    \u url
    。但这在构建邮件时不起作用

    通过在
    config/environments/production.rb
    中设置标志
    config.Force\u ssl=true
    ,强制应用程序始终在生产模式下使用ssl

    此外,在邮件程序中执行此操作时,您可能需要设置以下内容:

    # production.rb
    config.action_mailer.default_url_options = {
      host: 'yourdomain.com',
      protocol: 'https'
    }