意想不到的kENSURE,期待$ end - Rails / Cucumber / Haml

时间:2010-04-21 22:03:24

标签: ruby-on-rails cucumber haml

遇到了Rails / Cucumber / Haml的问题。下面的Haml文件在开发和实时环境中完美运行,但在Cucumber中失败,出现以下错误:

/app/views/competitions/show.haml:30: syntax error, unexpected kENSURE, expecting $end (ActionView::TemplateError)
On line #30 of app/views/competitions/show.haml

第30行是文件的结尾。它适用于Haml gem版本2.2.3但不适用于以后版本(我已经尝试过2.2.23,2.2.22,2.2.17)

- title @competition.name

%h1
  =h @competition.name

- if @competition.image?
  #main_image
    = image_tag(@competition.image_url)

= RedCloth.new(@competition.description).to_html

%h2
  =h @competition.question

%p 
  - if @competition.running?
    = link_to 'Enter competition', enter_path(:id => @competition.secret)
  - else
    = case @competition.state
      - when 'scheduled' then 'Competition has not opened'
      - when 'closed' then 'Competition closed'

if can? :update, @competition
  = link_to 'Edit', edit_competition_path(@competition)
  |

- if can? :show_stats, @competition
  = link_to 'View stats', competition_stats_path(@competition)

任何想法发生了什么?

1 个答案:

答案 0 :(得分:0)

根据我对黄瓜+ haml的经验,这类事情最常见的原因是方法调用的模糊性和haml在条件语中失去了对范围的追踪。尝试围绕所有方法包装括号。

在您发布的代码中,第一个if也缺少-

我还建议尝试将when case部分放入帮助程序,因为haml有时会对此类事情感到困惑,尤其是当它们设置为-时。

您正在运行哪个版本的Rails?