Rails Lib 文件加载错误
在我的项目中,我使用一些自定义液体标签,并在“lib”目录中创建了一个名为“Liquid”的文件夹,其中有一个名为 helpers 的液体模块,
module Liquid::Helpers
end
因此项目树如下所示
Root
--> 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
更新
-
我在Rails3和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>'
In my project I'm using some custom liquid tags and I have created a folder called 'Liquid' inside my 'lib' directory and there I have a liquid module called helpers,
module Liquid::Helpers
end
So the project tree is as follows
Root
--> lib
--> Liquid
And I'm trying to register my tags in my environment.rb file
Liquid::Template.register_filter(Liquid::Helpers)
To load my lib files when the server starts, I'm trying this in application.rb
config.autoload_paths << File.join(Rails.root.to_s, "lib")
But I'm getting the following error
': uninitialized constant Liquid::Helpers (NameError)
What am i missing here, can someone help me, thanks in advance
cheers
sameera
Update -
I'm on Rails3 with Ubuntu. Following is my full error code
`<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>'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的水平还不够高,无法提出澄清问题,但我的第一条建议是通过以下方式澄清您的问题(考虑在任何地方发布任何问题的可靠建议):
列出 Rails 的版本, Liquid、Gems、Ruby 等您正在使用的版本(尤其是 Rails 版本)
复制粘贴出现错误消息的终端的整个输出。虽然您可能不理解该输出,但对其他人调试您的情况很有用。从终端复制粘贴(包括您运行的命令)会留下零问题
提供有关文件结构的更好信息。终端复制粘贴再次完美。从 Rails 根目录中,您可以运行命令
find lib
(除非您使用的是 Windows,在这种情况下您无法使用 find,并且是时候考虑切换到 OSX 或 ubuntu)。这是一个终端复制粘贴的示例,其中包含所有这些信息:
...全部在一个终端中。
I'm not a high enough level yet to ask clarifying questions, but my first piece of advice is to clarify your question in the following way (consider this solid advice for posting any question anywhere):
list the versions of rails, liquid, gems, ruby, etc that you are using (especially the rails version)
copy-paste the entire output of your terminal where the error message is arising. While you may not understand that output, it is useful for someone else to debug your situation. Copy-pasting from the terminal (including the command you ran) leaves zero question
provide better info on your file structure. Once again a terminal copy-paste is perfect. From your rails root, you could run the command
find lib
(unless you're on Windows, in which case you can't use find and it's time to consider switching to OSX or ubuntu).Here's an example of a terminal copy-paste that includes all that information:
... all in one terminal.