2011-11-05 99 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