Force SSL for specific routes in Rails 3.1

我的未来我决定 提交于 2019-12-04 01:14:34
anshumans

I asked a similar question on stackoverflow here and was told to use https://github.com/tobmatth/rack-ssl-enforcer. I haven't tried it out yet, but based on the readme, it appears to solve your problem of conditionally enforcing ssl on certain routes.

Rails 4 with ActiveAdmin 1.0b, I modified config/initializers/active_admin.rb:

config.before_filter :force_ssl_redirect, if: :https_enabled?

force_ssl_redirect is defined in actionpack/lib/action_controller/metal/force_ssl.rb and is what Rails' force_ssl class method calls.

https_enabled? defined in my application_controller.rb:

def https_enabled?
  ENV['HTTPS_ENABLED'] == 'true'
end
blawzoo

You can do it this way:

controller

force_ssl :except => :index

view

supposing your index path name is index_landing_path

<%= link_to 'Landing', index_landing_path, :protocol => 'http' %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!