开发者

unexpected kENSURE, expecting $end - Rails/Cucumber/Haml

Been having a problem with Rails/Cucumber/Haml. The below Haml file works perfectly in the development and live environments but fails in Cucumber with the following error:

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

Line #30 is the en开发者_开发问答d of the file. It works in Haml gem version 2.2.3 but not in later ones (I've tried 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)

Any ideas what's happening?


In my experience with cucumber+haml, this sort of thing is most commonly caused by ambiguity in method calling and haml losing track of the scope in conditionals. Try wrapping parentheses around all your methods.

In the code you posted, the first if is also missing its -.

I'd also recommend trying putting the when case section into a helper as haml sometimes gets confused with things like that, especially as they are set with -.

Which version of Rails are you running?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜