导致 URL 的 href 值为: 0.0.0.0:3000/model_name/www.the_url_i_want.com -6ren">
gpt4 book ai didi

ruby-on-rails - 如何停止rails应用程序中的链接以域为前缀

转载 作者:行者123 更新时间:2023-12-04 18:14:43 26 4
gpt4 key购买 nike

这两个:

<%= content_tag("a", @a_model_instance.name, :href => @a_model_instance.url) %>
<a href="<%= @a_model_instance.url %>"><%= @a_model_instance.url %></a>

导致 URL 的 href 值为:
0.0.0.0:3000/model_name/www.the_url_i_want.com

你如何防止这种情况得到 a带有 href 的标签 www.the_url_i_want.com 的值? @a_model_instance.url返回字符串 www.the_url_i_want.com .

编辑-一种解决方案

这有效:
<%= content_tag("a", @a_model_instance.name, :href => "http://#{@a_model_instance.url}") %>
<a href="http://<%= @a_model_instance.url %>"><%= @a_model_instance.url %></a>

但似乎很不合规矩

最佳答案

如果您在 url 的开头添加 http 它不应该在我认为的域之前添加

关于ruby-on-rails - 如何停止rails应用程序中的链接以域为前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11956094/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com