Search code examples
ruby-on-railsslim-lang

Slim Rails Tables Using .each Over an Array


My table works fine when I put = list.title above the tr element, but when I move it below into a td cell, I get an undefined method list error. I am new to slim and templating engines. Can you suggest how to format this correctly? Also is there a thorough syntax guide our there on slim? I tried to Google around, but could not find exactly what I had hoped for.

table
        thead
          tr
              th
                  | Title
              th
                  | Description
              th
                  | Image URL
              th
                  | Price
        tbody
            - @products.each do |list|
            tr
              td
                = list.title
              td
                = list.description
              td
                = list.image_url

Solution

  • well there is indentation problem. You should have the tr tag and its children one indent inside. i.e. the - @products.each do |list| should enclose the items.

            - @products.each do |list|
              tr
                td
                  = list.title
                td
                  = list.description
                td
                  = list.image_url