- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我想要的字符串:
<a href="/pugs/1-baxter">Baxter</a> and <a href="/pugs/2-sofia">Sofia</a>
<%= @pugs.collect {|p| link_to(p.name, pug_path(p))}.to_sentence %>
<a href="/pugs/1-baxter">Baxter</a> and <a href="/pugs/2-sofia">Sofia</a>
html_safe
和
raw
,但它们似乎没有任何影响。
最佳答案
从 Rails 5 开始,有一个 to_sentence
执行此操作的 View 助手(不同于 Array#to_sentence
)。
来自 the docs :
to_sentence(array, options = {})
Converts the array to a comma-separated sentence where the last element is joined by the connector word. This is the html_safe-aware version of ActiveSupport's Array#to_sentence.
<% to_sentence(@pugs.collect {|p| link_to(p.name, pug_path(p))}) %>
关于ruby-on-rails - to_sentence 和 html_safe,一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696239/
.to_sentence方法中,如何获取last_word_connector输出HTML字符串? 例如: locations.to_sentence last_word_connector: ''
像这样的东西: John 向 user1、user2、user3 和 user4 发送消息 这行不通 @users.collect{ |u| link_to(u.name, user_path(u))
这是我想要的字符串: Baxter and Sofia 这是我用来输出的代码: 不幸的是,输出正在被编码: <a href="/pugs/1-baxter">Bax
ActiveSupport 提供了很好的方法to_sentence。因此, require 'active_support' [1,2,3].to_sentence # gives "1, 2, a
当我发现它是 deprecated 时,我刚开始使用“to_sentence”方法在 rails > 2.3.8 中。有谁知道为什么以及它是否已被替换?我发现它非常方便,不想失去那一点功能。 最佳答案
我是一名优秀的程序员,十分优秀!