【问题标题】:Escaping double quotes in Rails link_to在 Rails link_to 中转义双引号
【发布时间】:2012-08-12 19:10:03
【问题描述】:

我是 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="配对,然后一切都关闭

【问题讨论】:

  • 请显示您正在尝试的实际代码。它将帮助您获得更多答案。
  • 编辑了原始帖子以包含代码和输出

标签: ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:

你可以这样做:

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

【讨论】:

    【解决方案2】:

    link_to '“某事”'

    不工作?举个例子说明你想要什么

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-17
      • 2020-11-26
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2017-09-13
      相关资源
      最近更新 更多