Haml's problem of "illegal nesting"; How to place multiple code elements in the same tag?

- @subjects.each do |s| %tr %td= s.position %td= s.name %td= s.visible ? "Yes" : "No" %td= s.pages.size %td= link_to("Show", {:action => "show", :id => s.id}, :class => "action show") = link_to("Edit", {:action => "edit", :id => s.id}, :class => "action edit") = link_to("Delete", {:action => "delete", :id => s.id}, :class => "action delete") 

error_msg:

Illegal nesting: content cannot be specified on the same line as% td and is nested in it.

I want these three links to display, edit and delete in the same td; How can i do this?

+6
source share
2 answers

You just need to change this:

 %td= link_to("Show", {:action => "show", :id => s.id}, :class => "action show") = link_to("Edit", {:action => "edit", :id => s.id}, :class => "action edit") = link_to("Delete", {:action => "delete", :id => s.id}, :class => "action delete") 

:

 %td = link_to("Show", {:action => "show", :id => s.id}, :class => "action show") = link_to("Edit", {:action => "edit", :id => s.id}, :class => "action edit") = link_to("Delete", {:action => "delete", :id => s.id}, :class => "action delete") 

You must also retreat td from tr .

+13
source

FYI - I also ran into this problem, but the culprit was the final space after my <td> , which is the content for HAML.

0
source

Source: https://habr.com/ru/post/886564/


All Articles