Rails ActionView :: Helpers :: TagHelper的未定义方法

时间:2014-05-12 11:31:42

标签: ruby-on-rails haml rubinius

在预生产机器上运行rails时,我收到一个未定义的方法错误。错误消息如下所示:

undefined method `content_tag' for module `ActionView::Helpers::TagHelper'
  (in /home/user/my-rails-app/app/assets/javascripts/templates/general/test.mustache)

错误出现在布局文件中,包含' application.js':

<%= javascript_include_tag "application" %>

stacktrace看起来像这样:

kernel/delta/module.rb:39:in `alias_method'
haml (4.0.5) lib/haml/helpers/action_view_mods.rb:74:in `__script__'
haml (4.0.5) lib/haml/helpers/action_view_mods.rb:59:in `__script__'
haml (4.0.5) lib/haml/helpers/action_view_mods.rb:38:in `__script__'
haml (4.0.5) lib/haml/helpers/action_view_mods.rb:1:in `__script__'
kernel/common/code_loader.rb:243:in `require'
kernel/common/kernel.rb:705:in `require'
activesupport (4.0.2) lib/active_support/dependencies.rb:229:in `require'
activesupport (4.0.2) lib/active_support/dependencies.rb:214:in `load_dependency'
activesupport (4.0.2) lib/active_support/dependencies.rb:229:in `require'
haml (4.0.5) lib/haml/template.rb:3:in `__script__'
kernel/common/code_loader.rb:243:in `require'
kernel/common/kernel.rb:705:in `require'
activesupport (4.0.2) lib/active_support/dependencies.rb:229:in `require'
activesupport (4.0.2) lib/active_support/dependencies.rb:214:in `load_dependency'
activesupport (4.0.2) lib/active_support/dependencies.rb:229:in `require'
haml (4.0.5) lib/haml/railtie.rb:5:in `__script__'
kernel/common/eval.rb:43:in `instance_eval'
activesupport (4.0.2) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
activesupport (4.0.2) lib/active_support/lazy_load_hooks.rb:28:in `on_load'
kernel/bootstrap/array.rb:66:in `each'
activesupport (4.0.2) lib/active_support/lazy_load_hooks.rb:27:in `on_load'
haml (4.0.5) lib/haml/railtie.rb:4:in `__script__'
...

我认为这个错误是由于ActionView::Helpers::TagHelper模块在​​加载Haml时未定义content_tag这一事实。 (相关代码为here)。出于某种原因,此问题不会出现在其他相同的环境中。任何人都可以为此问题建议修复/解决方法吗?

[UPDATE]

这只发生在开发模式中。我使用的是rbx-2.2.6,actionpack 4.0.2版和haml 4.0.5

1 个答案:

答案 0 :(得分:0)

最近找到了解决方法。如果确保加载了操作视图,然后手动加载haml,则它可以正常工作。

在application.rb中,在需要rails之后,但在需要捆绑的gem之前:

require 'action_view'
require 'haml'

感谢艾萨克的灵感

相关问题