【问题标题】:Sinatra and Haml: strange behaviour after gem updateSinatra 和 Haml:gem 更新后的奇怪行为
【发布时间】:2011-06-23 03:48:07
【问题描述】:

我使用 Haml 和 Sinatra 创建了一个网站。更新后(我猜是在那之后)该网站不再工作了;这是一个最小的例子:

/app.rb:

require 'rubygems' if RUBY_VERSION < '1.9'
require 'sinatra'
require 'haml'

get "/" do
  haml :index
end

/views/layout.haml

!!!
%html{ :xmlns => "http://ww.w3.org/1999/xhtml", :lang => "en", "xml:lang" => "en" }
  %head
    %title test
  %body
    = yield

/view/index.haml

%p test

它抛出了以下异常:

/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.2/lib/tilt/template.rb in initialize
    raise ArgumentError, "file or block required" if (@file || block).nil?

/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in new
    template.new(path, 1, options)

/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in block in compile_template
    template.new(path, 1, options)

/usr/lib/ruby/gems/1.9.1/gems/tilt-1.3.2/lib/tilt.rb in fetch
    @cache[key] ||= yield

/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in compile_template
    template_cache.fetch engine, data, options do

/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in render
    template = compile_template(engine, data, options, views)

/usr/lib/ruby/gems/1.9.1/gems/sinatra-1.3.0.a/lib/sinatra/base.rb in haml
    render :haml, template, options, locals

我还没有真正找到解决方法,有人知道如何解释吗?

【问题讨论】:

    标签: sinatra haml


    【解决方案1】:

    我在使用 Sinatra 1.3.0.a(您正在使用的版本,我认为它是候选版本而不是完整版本)时遇到同样的错误,但更新到当前最新版本 (1.3.0.e)修复它,降级到最新的稳定版本(1.2.6)也是如此。所以你的答案是升级或降级。

    您可以使用以下方式加载特定版本的 gem:

    gem "sinatra", "=1.2.6"
    

    在您致电require "sinatra" 之前,或者您可以考虑使用Bundler(使用相同的语法)。

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 1970-01-01
      • 2012-06-24
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多