Rails Lib文件加载错误

时间:2010-12-10 16:07:39

标签: file ruby-on-rails-3 liquid

在我的项目中,我使用了一些自定义液体标签,我在'lib'目录中创建了一个名为'Liquid'的文件夹,在那里我有一个名为helpers的液体模块,

module  Liquid::Helpers

end

所以项目树如下

--> lib 

      --> Liquid

我正在尝试在environment.rb文件中注册我的标签

Liquid::Template.register_filter(Liquid::Helpers)

要在服务器启动时加载我的lib文件,我在application.rb

中尝试这个
config.autoload_paths <<  File.join(Rails.root.to_s, "lib")

但是我收到以下错误

':未初始化的常量Liquid :: Helpers(NameError)

我在这里缺少什么,有人可以帮助我,提前谢谢

欢呼声

sameera

更新 -

我在Uails上使用Ubuntu。以下是我的完整错误代码

`<top (required)>': uninitialized constant Liquid::Helpers (NameError)
    from <project path>/config.ru:3:in `require'
    from <project path>/config.ru:3:in `block in <main>'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
    from <project path>/config.ru:1:in `new'
    from <project path>/config.ru:1:in `<main>'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in `eval'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in `parse_file'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:162:in `app'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:248:in `wrapped_app'
    from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:213:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands/server.rb:65:in `start'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:30:in `block in <top (required)>'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:27:in `tap'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.0/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

1 个答案:

答案 0 :(得分:0)

我还没有达到澄清问题的水平,但我的第一条建议是以下列方式澄清你的问题(考虑这个在任何地方发布任何问题的可靠建议):

  • 列出您正在使用的rails,liquid,gem,ruby等版本(特别是rails版本)

  • 将终端的整个输出复制粘贴到出现错误消息的位置。虽然您可能无法理解该输出,但对其他人来说调试您的情况非常有用。从终端复制粘贴(包括您运行的命令)留下零问题

  • 提供有关文件结构的更好信息。终端复制粘贴再次完美。从您的rails根目录,您可以运行命令find lib(除非您在Windows上,在这种情况下您不能使用find,是时候考虑切换到OSX或ubuntu了。)

以下是包含所有信息的终端复制粘贴示例:

dhcp-c-200:foo luke$ rails -v && gem -v && ruby -v && gem list | grep liquid
Rails 2.3.5
1.3.5
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
dhcp-c-200:foo luke$ find lib
lib
lib/Liquid
lib/Liquid/some_module_file.rb
lib/tasks
dhcp-c-200:foo luke$ script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant Liquid::Template (NameError)
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
    from /Users/luke/Sites/foo/config/environment.rb:43
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:84
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from script/server:3
dhcp-c-200:foo luke$ cat lib/Liquid/some_module_file.rb 
module Liquid

end

module Liquid::Foo

enddhcp-c-200:foo luke$ 

...所有在一个终端。