倾斜模板引擎初始化

发布于 2024-10-29 11:04:42 字数 678 浏览 0 评论 0原文

我只是安装倾斜:

gem list
tilt (1.2.2)

ruby -v
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]

我只是尝试 https://github.com/rtomayko/tilt

倾斜.rb

require 'rubygems'
require 'haml'
require 'tilt'
template = Tilt::HamlTemplate.new('haml/about.haml')

它抛出:

./tilt.rb:4: uninitialized constant Tilt (NameError)
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `require'
    from tilt.rb:3

有什么想法吗? 谢谢!

I just install tilt :

gem list
tilt (1.2.2)

ruby -v
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]

And I simply try the basic example from https://github.com/rtomayko/tilt

tilt.rb

require 'rubygems'
require 'haml'
require 'tilt'
template = Tilt::HamlTemplate.new('haml/about.haml')

And it throw :

./tilt.rb:4: uninitialized constant Tilt (NameError)
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:29:in `require'
    from tilt.rb:3

Any idea ?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空心↖ 2024-11-05 11:04:42

您已将应用程序文件命名为 tilt.rb,因此当您调用 require 'tilt' 时,该文件会尝试 require 自身。您的文件未定义 Tilt,因此您会收到所看到的错误。

该错误实际上是在需要该文件时发生的。它不会陷入递归循环,因为 require 会跟踪所需的文件,并且不会尝试重新加载它们。

将文件重命名为 tilt.rb 以外的名称,例如 tilt-test.rb,并且不要将原始文件保留在同一目录中,它应该可以工作。

顺便说一句,这在 Ruby 1.9 中不会发生,因为默认情况下当前目录不在加载路径上。

You've named your application file tilt.rb, so when you call require 'tilt' the file tries to require itself. Your file doesn't define Tilt, so you get the error you see.

The error actually happens as the file is being required. It doesn't fall into recursive loop because require keeps track of the files that have been required, and doesn't attempt to reload them.

Rename your file to something other than tilt.rb, for instance tilt-test.rb, and don't leave the original file in the same directory, and it should work.

Incidentally, this doesn't happen in Ruby 1.9, since the current directory isn't on the load path by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文