Getting Rails URL helpers to automatically output https urls

橙三吉。 提交于 2019-11-30 02:50:00
Krishna Srihari

Use test_url(:protocol => 'https') for https urls.

apneadiving

Haven't tried but add this in your ApplicationController:

def default_url_options(options={})
 { :secure => true }
end 
i_emmanuel
def default_url_options(options={})
 { :protocol => "https" }
end

For Rails 3.2 I used a combination of @apneadiving's answer. Adding the below code to my ApplicationController

def default_url_options(options={})
  options.merge{ :protocol => "https" }
end
Joe Van Dyk

Rails 3 SSL routing redirects from https to http answers this question pretty well. In short, there's not a great way to do it. I submitted the following Rails bug: https://github.com/rails/rails/issues/3571

You can use a plugin called ss_requirement, it will provide you with methods like ssl_required ssl_allowed

You can simply add this in your controller to enable ot disable https on any action

ssl_allowed :login, :update_profile

https://github.com/rails/ssl_requirement

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