0

I'm using Slim in my Rails app and my table rows (tr) are not being interpreted inside a loop.

- 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

This is what it output in the browser:

table output

When I write the same table structure outside of the loop (see below) it works fine.

table
  tr
    td "Table row 1"
  tr
    td "Table row 2"
tigerdahl
  • 113
  • 7

1 Answers1

1

I changed my code to use the same convention as the Slim example code (https://github.com/slim-template/slim) and it solved the problem.

- 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>"
tigerdahl
  • 113
  • 7