简体   繁体   English

Rails 4 force_ssl问题?

[英]Rails 4 force_ssl issue?

Testing Rails 4. In Rails 3, putting force_ssl at the top of my controller forced ssl only for production. 测试Rails 4.在Rails 3中,将force_ssl放在我的控制器顶部强制ssl仅用于生产。 This was ignored for development, which was the behavior I wanted, and which conformed to the docs for force_ssl. 这被忽略了开发,这是我想要的行为,并且符合force_ssl的文档。

In Rails 4 I found that force_ssl forces ssl even for development, which is not the behavior I want (easy to work around, but requires more code which I don't want). 在Rails 4中,我发现force_ssl强制ssl甚至用于开发,这不是我想要的行为(易于解决,但需要更多我不想要的代码)。 Furthermore, I can't find where this was supposedly changed in any release notes, so I believe it could be a bug. 此外,我无法在任何发行说明中找到所谓的更改位置,因此我认为它可能是一个错误。

I haven't been able to find a bug report on this through googling, nor on this website. 我无法通过谷歌搜索找到关于此的错误报告,也无法在本网站上找到。 Can anyone else confirm? 其他人可以确认吗? Furthermore, if so, can someone submit the bug report to Rails (I don't have an account set up to do so, and don't want to create one if someone else already has one). 此外,如果是这样,有人可以将错误报告提交给Rails(我没有设置这样做的帐户,并且如果其他人已经拥有帐户,则不想创建一个帐户)。

Easy workaround, btw: 简单的解决方法,顺便说一下:

Rails.env.production? ? force_ssl : nil

It's not a bug- https://github.com/rails/rails/pull/5023 这不是一个错误 - https://github.com/rails/rails/pull/5023

The solution given there for your issue is 为您的问题提供的解决方案是

force_ssl unless Rails.env.development?

If, like me, you have force_ssl a lot of places in your code you can keep DRY with an initializer: 如果像我一样,你在代码中有很多地方使用force_ssl你可以使用初始化程序保持DRY:

module ActionController::ForceSSL::ClassMethods
  alias_method :original_force_ssl, :force_ssl
  def force_ssl(options={})
    original_force_ssl unless Rails.env.development?
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM