在所有 Rails 助手中将协议更改为 https [英] Change protocol to https in all rails helpers

查看:17
本文介绍了在所有 Rails 助手中将协议更改为 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 3.1+我希望我的 url 助手使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆