简体   繁体   English

对rails中的特定控制器跳过/禁用force_ssl

[英]skip/disable force_ssl for particular controller in rails

I need to force SSL on all routes in my application except for message#new controller. 我需要在我的应用程序中的所有路由上强制使用SSL,除了message#new controller。

In config/environments/production.rb , I have: config/environments/production.rb ,我有:

config.force_ssl = true

Now all routes being redirect to https, And now I want to disable that for message#new controller. 现在所有路由都重定向到https,现在我想禁用message#new controller。

Does anyone know how to disable force SSL for particular controller in a Rails 4+ application? 有谁知道如何在Rails 4+应用程序中禁用特定控制器的强制SSL?

according to documentation following should work ( but only for rails > 5 version ): 根据以下文档应该工作( 但仅适用于rails> 5版本 ):

config.ssl_options = {
  redirect: {
    exclude: -> request { request.path =~ /healthcheck/ }
  }
}
skip_before_action :verify_authenticity_token
force_ssl except: [:index,:create]

Its worked for me. 它对我有用。

MessagesController.rb执行此操作 -

  force_ssl except: [:new]

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

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