我在 application_controller.rb 中有两个方法
def force_ssl
if !request.ssl?
redirect_to :protocol => 'https'
end
end
def no_ssl
if request.ssl?
redirect_to :protocol => "http"
end
end
我还在 application.rb 中完成了 before_filter :no_ssl
现在我正尝试在设计的 session Controller 中调用 force_ssl 方法以通过 SSL 安全登录
在 sessions_controller.rb 文件中,我完成了 skip_before_filter :no_ssl 和 before_filter :force_ssl
当我使用它时我无法登录,但是如果我不在 application_controller.rb 中执行 before_filter :no_ssl
它工作正常。
因为我有很多 Controller ,所以我试图将 before_filter :no_ssl
放在 application.rb 中,这样我就不必在所有的 Controller ,因为它不会干燥。
我已经尝试了几乎所有可用的资源,但不知道为什么这不起作用。
P.S :- 这适用于我的其他 Controller ,除了设计 Controller 有什么建议吗??
谢谢,
最佳答案
您可以使用 Bartt-SSL_Requirement,它在 Rails 3.1 中运行良好,这样您就不需要 before_filter 和 skip_before_filter。在 BarttSSLRequirement 中,您可以使用“ssl_exceptions”来满足您的 before_filter 需求。
SSL 有时会在开发中出现问题,将其推到暂存区,它应该可以工作。
关于ruby-on-rails-3 - SSL on Devise 无法正常工作 Rails 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8148062/