Rails 3,从 https 重定向到 https,覆盖 _path helper
我想要混合 https/http 网站。
此外,我希望从 https 重定向到 http(即用户成功登录后,它应该重定向到 http 的根页面)。
像以下这样的宝石:
- rack-sslrack
- -ssl-enforcer
可以完美工作,但前提是您想在 https 上拥有整个网站 “混合 http/https”在 A、B、C 操作中仅使用 ssl,而在 D、E、F 操作中仅使用 http - 不起作用。
我检查了另一个 SO 线程的解决方案:
几乎可以工作。 编写脚本很容易,它将(在整个视图上)助手从“_path”更改为“_url”。
但是链接存在一个问题,例如:
<%= link_to "model", some_model %>
<%= link_to "edit model", edit_mode_url(model) %>
...
有许多不同的模型,并且我经常在迭代块中使用“模型”,因此基于“重写”脚本的解决方案将不起作用。
问题:
有没有办法改变 <%= link_to 'model', model %>
代码的行为来解决这个问题?是否有可能覆盖路径助手(标准协议将是 http,在给定参数上 - https)?
或者也许还有另一种我还没有找到的解决方案?
编辑:
我使用 Rails 3.0.9。
I want to have mixed https/http site.
Moreover I want have redirects from https to http(ie. after user login successfully it should redirect to root page at http).
Gems like:
- rack-ssl
- rack-ssl-enforcer
works perfectly but only If you want to have entire site at https
"Mixed http/https" with only ssl at A, B, C actions and only http at D, E, F - dont work.
I checked solution from another SO thread:
Rails 3 SSL routing redirects from https to http
Almost works.
Its easy to write script which will change(on entire views) helper from "_path" to "_url".
But there is a problem with links like:
<%= link_to "model", some_model %>
<%= link_to "edit model", edit_mode_url(model) %>
...
There are many diffrent models and I use often "model" at iteration blocks, so solution based on 'rewrite' script will dont work with that.
Questions:
Is there a way to change behavior of <%= link_to 'model', model %>
code to fix that? Is there a possibility to overwrite path helper(standard protocol will be http, on giver parameter - https)?
Or maybe there is a another solution which I have not found yet?
Edit:
I work with Rails 3.0.9.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想将 https 添加到特定路由,
您可以使用此代码
您只需执行以下操作即可定义要与 before_filter 操作一起使用的路由
If you would like to add https to a particular route
you can use this code
You can define the routes you would like to use with the before_filter action simply by doing the following
使用这个gem:
https://github.com/retr0h/ssl_requirement
gem install ssl_requirement
然后添加
ssl_required :new, :destroy #others actions
到您的控制器。
如果您使用设计,则必须覆盖每个控制器并指定所有操作
它适用于 Rails 3.0.x
Use this gem:
https://github.com/retr0h/ssl_requirement
gem install ssl_requirement
Then to add
ssl_required :new, :destroy #others actions
to your controllers.
If you use devise you have to overwrite each controller and specify all actions
It works with Rails 3.0.x