2013-04-24 64 views
0

這是我在我的Padrino應用程序中的代碼,我找不到它是什麼行或錯誤。該錯誤消息「語法錯誤,意想不到的keyword_end期待$結束」內容類型case語句中的語法錯誤

get :index, :provides => [:html, :json] do 
    @title = "Restaurants" 
    @restaurants = Restaurant.all 

    case content_type 
     when :json 
     render @restaurants 
     else 
     render 'restaurants/index' 
     end 
    end 
    end 

可否請你指出我的錯誤,並建議我怎麼可能調試它的未來?謝謝

回答

1

你有一個備用end關鍵字。 你應該刪除一個。

在代碼中有一些縮進。保持正確的縮進有助於避免此類錯誤。我建議縮進你這樣的代碼:

get :index, :provides => [:html, :json] do 
    @title = "Restaurants" 
    @restaurants = Restaurant.all 

    case content_type 
    when :json 
    render @restaurants 
    else 
    render 'restaurants/index' 
    end 
end 
0

試試這個:

get :index, :provides => [:html, :json] do 
    @title = "Restaurants" 
    @restaurants = Restaurant.all 

    case content_type 
     when :json 
     render @restaurants 
     else 
     render 'restaurants/index' 
     end 

    end 
1

有一個end太多。

對代碼縮進要小心,這永遠不會成爲問題。關於它如何在Vim下看的例子。我剛剛使用了= G,它爲我對齊。另外,它只會突出顯示end的正確使用。你最喜歡的編輯器應該也有這個功能。如果沒有,請切換。

enter image description here

+0

好的提示!我也使用Vim。謝謝 – Peter 2013-04-24 23:00:39