Haml: Erubi superclass mismatch

Created on 4 Aug 2017  Â·  11Comments  Â·  Source: haml/haml

Error description

Attempting to run a Rails application with better_errors 2.3.0 which has a dependency to erubi (instead of erubis as in 2.2.0) results in the following error

.bundle/ruby/2.4.0/gems/haml-5.0.2/lib/haml/helpers/safe_erubi_template.rb:5: warning: toplevel constant Erubi referenced by ActionView::Template::Handlers::ERB::Erubi
rails aborted!
TypeError: superclass must be a Class (Module given)
.bundle/ruby/2.4.0/gems/haml-5.0.2/lib/haml/helpers/safe_erubi_template.rb:5:in `<module:Haml>'
.bundle/ruby/2.4.0/gems/haml-5.0.2/lib/haml/helpers/safe_erubi_template.rb:4:in `<top (required)>'
.bundle/ruby/2.4.0/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:293:in `require'
.bundle/ruby/2.4.0/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:293:in `block in require'

Configuration

  • rails 5.0.5
  • haml 5.0.2
  • haml-rails 1.0.0
  • better_errors 2.3.0

Most helpful comment

I had this problem also and fixed gem Better Errors to 2.2.0.
But today my app broke again with the same error.
This time the cause is i18n-tasks 0.9.17! Fixing this to 0.9.16 is a workaround.

Hope this helps somebody.

All 11 comments

I get this error in Rails 4 as well.

  • haml 5.0.2
  • better_errors 2.3.0
  • hame-rails 1.0.0
  • rails 4.2.8

Removing better_errors avoid the problem.

better_errors 2.3.0 adds a dependency on erubi. This can be reproduced by adding erubi to the Gemfile, regardless of whether better_errors is in the Gemfile.

Once Erubis has been added to the bundle, haml chooses Erubi. In rails 5.0.5, the exception occurs on the class declaration line of lib/haml/helpers/safe_erubi_template.rb:

module Haml
  class ErubiTemplateHandler < ActionView::Template::Handlers::ERB::Erubi

ActionView::Template::Handlers::ERB::Erubi is a very mysterious object, but it seems to be a pure reference to the Erubi module, which also explains the warning:

> Where.is(ActionView::Template::Handlers::ERB::Erubi)
(pry):1: warning: toplevel constant Erubi referenced by ActionView::Template::Handlers::ERB::Erubi
=> ["/usr/local/var/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/erubi-1.6.1/lib/erubi.rb", 24]

I can find no direct declaration of ActionView::Template::Handlers::ERB::Erubi in actionview, erubi, haml, or haml-rails. But according to that, it is a copy of Erubi and has no other methods.

I've narrowed it down a bit: any constant referenced under ActionView::Template's namespace causes a reference to that constant in the root namespace:

> ActionView::Template::Erubi
(eval):1: warning: toplevel constant Erubi referenced by ActionView::Template::Erubi
> ActionView::Template::ActionView
(eval):1: warning: toplevel constant ActionView referenced by ActionView::Template::ActionView
> defined? ActionView::Template::Handlers::ERB::Erubi
=> "expression"
> defined? ActionView::Template::Handlers::ERB::sdfsdf
=> nil
> defined? ActionView::Template::Handlers::ERB::ActionView
=> "constant"

I've opened #948 to fix this.

Thanks for tracing this down, sounds like you had a bit of fun there.

On Tue, Aug 8, 2017 at 2:53 PM Robin Daugherty notifications@github.com
wrote:

I've opened #948 https://github.com/haml/haml/pull/948 to fix this.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/haml/haml/issues/946#issuecomment-321048633, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAH_kM6UUUnGmpu4Q8DljFSkdD6U6PXks5sWK6ugaJpZM4OuAVp
.

I had this problem also and fixed gem Better Errors to 2.2.0.
But today my app broke again with the same error.
This time the cause is i18n-tasks 0.9.17! Fixing this to 0.9.16 is a workaround.

Hope this helps somebody.

Seems to work fine with Better Errors 2.2.0. Thanks!

I want people in this issue to test latest master branch of Haml including https://github.com/haml/haml/pull/948. Thanks!

Sorry for early merge, but could you guys try master including https://github.com/haml/haml/pull/952?

Works for me! Thank you.

On Fri, Aug 18, 2017 at 12:21 AM Takashi Kokubun notifications@github.com
wrote:

Sorry for early merge, but could you guys try master including #952
https://github.com/haml/haml/pull/952?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/haml/haml/issues/946#issuecomment-323255535, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAH_hNER0VSgtIDqnwURHQNAMF6LfFyks5sZRFRgaJpZM4OuAVp
.

Works fine for my project as well. Thanks!

  • Ruby v2.4.1
  • Rails v5.0.5
  • haml-rails v1.0.0
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Arcovion picture Arcovion  Â·  11Comments

pib picture pib  Â·  4Comments

atomAltera picture atomAltera  Â·  7Comments

dparis picture dparis  Â·  16Comments

tisba picture tisba  Â·  10Comments