Rails Haml:link_to glyphicon List Item - 非法嵌套

时间:2017-02-09 11:51:27

标签: ruby-on-rails haml

我的字形设置如下:

 = link_to edit_user_registration_path(pin.user_id), class: "btn btn-default"  do
    %span.glyphicon.glyphicon-cog

然而,当我把它放在%li中时,我得到了一个非法的嵌套错误:

%ul.nav.navbar-nav.navbar-right.custom
   %li= link_to edit_user_registration_path(pin.user_id), class: "btn btn-default" do
      %span.glyphicon.glyphicon-cog

我得到以下内容:

Illegal nesting: content can't be both given on the same line as %li and nested within it.

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

link_to方法放在下一行:

%ul.nav.navbar-nav.navbar-right.custom
  %li
    = link_to edit_user_registration_path(pin.user_id), class: "btn btn-default" do
      %span.glyphicon.glyphicon-cog

生成:

<ul class="nav navbar-nav navbar-right custom">
  <li>
    <%= link_to edit_user_registration_path(pin.user_id), class: "btn btn-default" do %>
      <span class="glyphicon glyphicon-cog"></span>
    <% end %>
  </li>
</ul>

您可以使用haml2erb.org进行测试。