Haml -Illegal nesting:在纯文本中嵌套是非法的

时间:2012-11-23 06:33:40

标签: ruby-on-rails ruby-on-rails-3 haml

我在使用HAML时我的代码中遇到了一个奇怪的错误,我的代码在我的本地机器上运行,但是当我部署它时,我收到以下错误

  

ActionView :: Template :: Error(非法嵌套:在纯文本中嵌套是非法的。):

我的代码看起来像这样

  %td{ :style => 'width:10px' }
= link_to('Dashboard',   dashboard_admin_clients_account_path(client)) if client.is_member?
= link_to('Edit',   edit_admin_clients_account_path(client))
- if client.removed_at.nil?
  = link_to('Delete', admin_clients_account_path(client), :method => :delete, :confirm => 'Are you sure you want to delete')
- else
  = link_to('Restore', restore_admin_clients_account_path(client))

我是HAML的新手

1 个答案:

答案 0 :(得分:8)

  1. 如果您希望您的链接位于%td内,则它们应该是1个选项卡(td-0选项卡,链接 - 左侧的1个选项卡)
  2. 您应该使用相同的方法来进行缩进(例如,始终使用制表符空格)。
  3. 看起来问题不在此代码中。它是部分原因还是其他代码的一部分?
  4. 因为“非法筑巢”通常会在您这样做时发生:

    %td{ :style => 'width:10px' }
        justtext
          =link_to ....
    

    试用此代码:

    %td{ :style => 'width:10px' }
        = link_to('Dashboard',   dashboard_admin_clients_account_path(client)) if client.is_member?
        = link_to('Edit',   edit_admin_clients_account_path(client))
        - if client.removed_at.nil?
            = link_to('Delete', admin_clients_account_path(client), :method => :delete, :confirm => 'Are you sure you want to delete')
        - else
            = link_to('Restore', restore_admin_clients_account_path(client))