【问题标题】:What's the best way to make a Ruby on Rails helper for your secure url path?为您的安全 url 路径制作 Ruby on Rails 助手的最佳方法是什么?
【发布时间】:2011-06-07 04:51:25
【问题描述】:

我来自 PHP 和 Python/GAE 背景,是 RoR 的新手。通常我会设置一个全局变量,其中包含我的不安全和安全网页的 url,用于模板时使用。例如,如果我想链接到图像,而不是说 img src="www.mysite.com/images/img1.png" 我可以使用 img src="{{ unsecure_url }}images/img1.png"。

我认为在 RoR 中执行此操作的最佳方法是将以下内容添加到我的 application_helper。这有效吗?

def unsecure_url
  "http://localhost:3000/"
end

def secure_url
  "https://localhost:3000/"
end

以及如何在本地环境和生产环境之间切换,这取决于我是否在本地环境中?

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    如果您使用预先存在的帮助程序,它们应该为当前协议和域生成相关链接。

    看看link_toimage_tag

    【讨论】:

      猜你喜欢
      • 2010-12-08
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 2015-03-03
      • 1970-01-01
      相关资源
      最近更新 更多