倾斜模板引擎初始化
我只是安装倾斜:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已将应用程序文件命名为
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 callrequire 'tilt'
the file tries to require itself. Your file doesn't defineTilt
, 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 instancetilt-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.