2010-04-21 32 views
3

一直有一個問題,導軌/黃瓜/火腿。下面Haml的文件完全在發展和生活環境,但未能在黃瓜以下錯誤:

/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的寶石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) 

任何想法發生了什麼?

+2

很難說沒有在我面前的實際代碼發生了什麼。嘗試暫時刪除一個代碼塊,然後查看其效果。開始縮小範圍。例如,嘗試刪除包含'%p'塊的所有內容,然後重新運行測試。 – 2010-04-21 23:19:33

+0

24號線上,你的意思是逃避嗎? :更新,@競爭'被解釋爲紅寶石代碼前面用連字符? ' - 如果可以? :更新,@競爭'。 – 2011-03-23 01:12:46

+0

有沒有機會在這個HAML文件被調用之前有'ensure..end'異常處理塊?在我看來,'ensure'在沒有適當的'end'的情況下被調用,並且HAML文件恰好在錯誤的時間出現在錯誤的地方。錯誤可能與此文件無關。 – 2011-05-27 02:42:14

回答

0

在我使用cucumber + haml的經驗中,這種事最常引起方法調用的不明確性和haml在條件中失去範圍跟蹤。嘗試在所有方法中包圍圓括號。

在您發佈的代碼中,第一個if也缺少其-

我還建議您嘗試將when case部分放入幫助程序中,因爲haml有時會與此類事物混淆,尤其是因爲它們設置爲-

您正在運行哪個版本的Rails?

相關問題