【问题标题】:Sinatra is ignoring my layout.hamlSinatra 忽略了我的 layout.haml
【发布时间】:2011-12-22 13:05:25
【问题描述】:

启动一个基本的 Sinatra 应用程序。它似乎没有使用我的布局模板。如果我在 layout.haml 中放入垃圾,我会收到 Sinatra 500 错误页面,说明它不是格式正确的 haml 文件。运行 Ruby 1.9.2。今晚在 Windows 上安装了 Sinatra、Haml 和 Rack 的 gem。

应用代码:

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

set :haml, :format => :html5

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

应用的位置/views/layout.haml

%html
  %body
    = yield

生成的“http://localhost:4567/”页面的来源

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

^请注意我的布局缺失。

【问题讨论】:

    标签: ruby sinatra haml


    【解决方案1】:

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

    应用代码:

    require 'sinatra'
    require 'haml'
    
    get '/' do
      haml :hello
    end
    

    views/hello.haml:

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

    views/layout.haml:

    %html
      %body
        = yield
    

    【讨论】:

    • 我在你发帖前几分钟就想到了同样的事情,但无论如何谢谢!我曾假设 Sinatra 会将我的“引用文本”包装在布局模板中,但我想事实并非如此!
    猜你喜欢
    • 2012-07-20
    • 2017-12-09
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    • 2013-12-08
    • 2016-11-17
    相关资源
    最近更新 更多