gpt4 book ai didi

ruby-on-rails - 在 Rails link_to 中转义双引号

转载 作者:太空宇宙 更新时间:2023-11-03 18:25:27 25 4
gpt4 key购买 nike

我是 Rails 框架和 Ruby 语言的新手,但我确实有一些编程和 MVC 经验。我正在尝试使用 rails 的 link_to 方法输出链接。但是在 HTML 中,此链接位于另一组双引号内。我需要在标签中转义 rails 产生的引号。

我试过谷歌,只找到了 javascript 转义的信息,但没有帮助。我尝试使用多次提到的 h(%[]) 方法,但随后未创建链接,实际单词 link_to 被输出。

有谁知道如何转义 Rails 创建的超链接标记中的双引号或将其切换为使用单引号?

实际代码

<% @properties = Property.all 
@properties.each do |property| %>
<img src="images/img<%= property.id %>.jpg" alt="" title="<strong><%= property.address %></strong><span>9 rooms, 3 baths, 6 beds, building size: 5000 sq. ft. &nbsp; &nbsp; &nbsp; Price: $ 600 000 &nbsp; &nbsp; &nbsp; <%= link_to "Read More", property) %></span>">
<% end %>

输出

<img src="images/img1.jpg" alt="" title="<strong>50 Craft LAne</strong><span>9 rooms, 3 baths, 6 beds, building size: 5000 sq. ft. &nbsp; &nbsp; &nbsp; Price: $ 600 000 &nbsp; &nbsp; &nbsp; <a href="/properties/1">Read More</a></span>">

超链接中的第一个双引号与 title="配对,然后一切都关闭了

最佳答案

你可以这样做:

<%= link_to("Read More", property).gsub("\"", "'") %>

关于ruby-on-rails - 在 Rails link_to 中转义双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11925031/

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