Sinatra忽略了我的layout.haml

far*_*arr 2 ruby haml sinatra

启动基本的Sinatra应用程序.它似乎没有使用我的布局模板.如果我在layout.haml中放入垃圾,我会收到有关它的Sinatra 500错误页面,而不是正确形成的haml文件.运行Ruby 1.9.2.在Windows上,今天晚上安装了Sinatra,Haml和Rack的宝石.

应用代码:

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

set :haml, :format => :html5

get '/' do
  "Hello world, it's #{Time.now} at the server!"
end
Run Code Online (Sandbox Code Playgroud)

App的位置/ views/layout.haml

%html
  %body
    = yield
Run Code Online (Sandbox Code Playgroud)

生成的源"http:// localhost:4567 /"页面

Hello world, it's 2011-11-05 02:25:48 -0400 at the server!
Run Code Online (Sandbox Code Playgroud)

^注意我的布局不足.

War*_*Hog 6

为此,你必须说你的模板引擎在运行,如下所示:

应用代码:

require 'sinatra'
require 'haml'

get '/' do
  haml :hello
end
Run Code Online (Sandbox Code Playgroud)

意见/ hello.haml:

%p= "Hello world, it's #{Time.now} at the server!"
Run Code Online (Sandbox Code Playgroud)

意见/ layout.haml:

%html
  %body
    = yield
Run Code Online (Sandbox Code Playgroud)