0

I am getting an undefined method error when running rails on a preproduction machine. The error message looks like this:

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

The error appears in the layout file, on the line that includes 'application.js':

<%= javascript_include_tag "application" %>

The stacktrace looks like this:

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__'
...

I believe this error is due to the fact that the ActionView::Helpers::TagHelper module does not have content_tag defined at the time that Haml is loaded. (The relevant code is here). For some reason, this issue does not appear in other identical environments. Can anyone suggest a fix/workaround for this issue?

[UPDATE]

This only happens in development mode. I am using rbx-2.2.6, actionpack version 4.0.2, and haml 4.0.5

Slicedpan
  • 4,995
  • 2
  • 18
  • 33
  • I'm seeing something similar in a Sinatra app but only in production: `uninitialized constant Haml::ActionView` from `haml-4.0.5/lib/haml/template/plugin.rb:4`. All I needed to do was `require 'action_view/template/handlers/erb'` before `require 'haml/template/plugin'` – Isaac Betesh Aug 28 '14 at 19:20

1 Answers1

0

Found a workaround recently. If you ensure that action view is loaded and then manually load haml, it works correctly.

In application.rb, after requiring rails, but before requiring bundled gems:

require 'action_view'
require 'haml'

Thanks to Isaac for inspiration

Slicedpan
  • 4,995
  • 2
  • 18
  • 33