我有一个很小的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
我想这个问题与嵌套有关,但我看不到它。谁能帮我吗?
该错误消息通常表示您错过了do
迭代器的子句。就您而言,您在HAML中的Ruby子句无效,特别是同时使用afor
和枚举器(#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
评估为真实值的条目,然后对其余值进行迭代,从而为您提供选择标准和迭代。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句