haml错误消息:期待keyword_end等

时间:2014-11-19 21:10:00

标签: ruby-on-rails haml

我有一个小haml文件导致各种无理错误消息。该文件是这样的:

%h1 Collaborator List for Private Wiki "#{@wiki.title}"
- for @wiki.relationships.each do |r|
  - if !r.created_creator do
    %h3 Users.email.where(relationship=r)

错误消息是:

/home/vagrant/code/blocipedia/app/views/wikis/collaborator_list.html.haml:4: syntax error, unexpected keyword_ensure, expecting keyword_end ...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer.... ... ^ /home/vagrant/code/blocipedia/app/views/wikis/collaborator_list.html.haml:4: syntax error, unexpected ';', expecting :: or '[' or '.' /home/vagrant/code/blocipedia/app/views/wikis/collaborator_list.html.haml:7: syntax error, unexpected end-of-input, expecting keyword_end

我想这个问题与嵌套有关,但我看不到它。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:4)

该错误消息通常意味着您错过了迭代器的do子句。在您的情况下,HAML中的Ruby子句无效,特别是使用for和枚举器(#each)以及do之后的if

%h1 Collaborator List for Private Wiki "#{@wiki.title}"
- @wiki.relationships.each do |r|
  - if !r.created_creator
    %h3 Users.email.where(relationship=r)

但是你可以做得更好一些:

%h1 Collaborator List for Private Wiki "#{@wiki.title}"
- @wiki.relationships.reject(&:created_creator).each do |r|
  %h3 Users.email.where(relationship=r)

首先拒绝r.created_creator评估为真值的关系中的所有条目,然后迭代剩余的值,为您提供选择标准和迭代。

相关问题