2012-11-23 33 views
16

我在我的代码面临着一个奇怪的错误,而使用HAML在我的代码工作在我的本地机器,但是当我部署它,我收到以下错误Haml的-Illegal嵌套:纯文本内筑巢是非法

::的ActionView ::模板出错(非法嵌套:纯文本内筑巢是非法的。):

我的代码看起来像这样

%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

+0

我遇到了一些麻烦找到这个问题的原因因为错误是在用render渲染的部分内部,但是堆栈跟踪指向了父级。 –

回答

7
  1. 如果你希望你的链接是%TD里面,他们应该是1个点对点(TD - 0标签,链接 - 从左侧1个标签)
  2. 你应该用同样的方法,使缩进(例如总是使用tab instad空格)。
  3. 看起来问题不在于此代码中。它是部分代码还是其他代码的一部分?

因为 '非法筑巢' 当你做这样的通常发生:

%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)) 
+0

是的,这是我的部分,但代码在我的本地机器上工作正常 –

+0

你可以写代码之外提到的? – vekozlov