2011-11-05 31 views
0

開始一個基本的Sinatra應用程序。它似乎沒有使用我的佈局模板。如果我把我的layout.haml中的垃圾,我得到Sinatra 500錯誤頁面關於它不是一個正確形成的haml文件。運行Ruby 1.9.2。在Windows上,今天晚上安裝了Sinatra,Haml和Rack的寶石。Sinatra忽略我的layout.haml

應用代碼:

require 'rubygems' 
require 'sinatra' 
require 'haml' 

set :haml, :format => :html5 

get '/' do 
    "Hello world, it's #{Time.now} at the server!" 
end 

應用程序的位置/視圖/ layout.haml

%html 
    %body 
    = yield 

源產生的 「HTTP://本地主機:4567 /」 頁面

Hello world, it's 2011-11-05 02:25:48 -0400 at the server! 

^請注意缺少我的佈局。

回答

5

爲此,你不得不說,在行動的模板引擎,像這樣:

應用代碼:

require 'sinatra' 
require 'haml' 

get '/' do 
    haml :hello 
end 

的意見/ hello.haml:

%p= "Hello world, it's #{Time.now} at the server!" 

views/layout.haml:

%html 
    %body 
    = yield 
+0

在發佈之前的幾分鐘裏,我想到了同樣的事情,不過謝謝! 我曾經假定Sinatra會在佈局模板中包裹我的「引用文本」,但我猜並非如此! – farr