在所有rails帮助程序中将协议更改为https [英] Change protocol to https in all rails helpers
本文介绍了在所有rails帮助程序中将协议更改为https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Rails 3.1+
我希望我的网址助手使用https协议,而不必在我调用的每个帮助程序中指定它。
搜索后我发现了各种各样的方法但没有工作,例如:
Rails 3.1+ I want my url helpers to use the https protocol without having to specify it in every helper I call. After searching around I've found various ways but none work, for example:
ROUTES_PROTOCOL = (ENV["RAILS_ENV"] =~ /development/ ? 'http://' : 'https://')
scope :protocol => ROUTES_PROTOCOL, :path => "/app" do
如何做到这一点?
推荐答案
如果您使用的是Rails 4,则定义 ApplicationController#default_url_options
不起作用。 URL选项现在在应用程序的路由配置中定义:
If you are using Rails 4, defining ApplicationController#default_url_options
doesn't work. URL options are now defined in the application's routes config:
Rails.application.routes.draw do
default_url_options protocol: :https
end
这篇关于在所有rails帮助程序中将协议更改为https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文