我在我的Rails应用程序中使用Slim,而我的表行(tr)没有在循环中解释。
- if @item.suggestions.size > 0
table
- @item.suggestions.each do |suggestion|
tr
td=raw "<i>Posted by " + Shopper.find(suggestion.shopper_id).name + " at " + suggestion.created_at.to_formatted_s(:short) + ":</i>"
tr
td= suggestion.comment
这是它在浏览器中输出的内容:
当我在循环外部编写相同的表结构时(见下文),它可以正常工作。
table
tr
td "Table row 1"
tr
td "Table row 2"
答案 0 :(得分:1)
我将我的代码更改为使用与Slim示例代码(https://github.com/slim-template/slim)相同的约定,它解决了问题。
- if @item.suggestions.any?
table#suggestions
- for suggestion in @item.suggestions
tr
td= suggestion.comment
tr
td=raw "<i>Posted by " + Shopper.find(suggestion.shopper_id).name + " at " + suggestion.created_at.to_formatted_s(:short) + ":</i>"