让 Rails URL helper 自动输出 https url [英] Getting Rails URL helpers to automatically output https urls

查看:17
本文介绍了让 Rails URL helper 自动输出 https url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个混合了 http 和 https 的网站 - 使链接使用正确的路由协议的最佳/最简单的方法是什么 - 可以在路由文件中指定吗?

假设我在 Rails 3 中有以下路线.

匹配 "/test" => "test#index", :as => :test, :constraints => { :protocol => 'https' }

如果我在 http 页面上,并且我使用 test_url(),它会输出 http://domain.com/test.我想要 https://domain.com/test.

我知道我可以使用 test_url(:secure => true),但这是重复的逻辑.

我知道我可以让 http://domain.com/testhttps://domain.com/test,但这是一个额外的重定向,而且它在表单帖子上失败.

想法?

解决方案

看起来这个问题会在 Rails 4 中解决!https://github.com/rails/rails/commit/9b4514c3b8ecfbc45c40a24

I am developing a site that mixes http and https a lot - whats the best/easiest way to make the links use the right protocol for the route - can it be specified in the routes file?

Say I have the following route in Rails 3.

match "/test" => "test#index", :as => :test, :constraints => { :protocol => 'https' }

If I'm on a http page, and I use test_url(), it'll output http://domain.com/test. I want https://domain.com/test instead.

I know I can use test_url(:secure => true), but that's duplicating logic.

I know I could have http://domain.com/test to https://domain.com/test, but that's an extra redirect, plus it fails on form posts.

Ideas?

解决方案

It looks like this will be solved in Rails 4! https://github.com/rails/rails/commit/9b4514c3b8ecfbc40a44dbd4c2ebd4ce67f4a459

这篇关于让 Rails URL helper 自动输出 https url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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