Administrate: Autoloading punditize fails with Zeitwerk + Rails 6 (rc1) if not using punditize

Created on 6 May 2019  路  4Comments  路  Source: thoughtbot/administrate

If you look at the explanation of https://github.com/fxn/zeitwerk/issues/45, it is clear why this happens:

  • given pundit is not defined,

    • it tries to load the file /administrate-0.11.0/app/controllers/concerns/administrate/punditize.rb

    • it (correctly) does NOT define Administrate::Punditize

    • it errors with eager_load: expected <file> to define constant Administrate::Punditize

A solution would be:

  • don't auto require/load this
  • always define Administrate::Punditize, but keep it empty if Pundit doesn't exist

Most helpful comment

as a workaround - add gem 'pundit' to Gemfile and it will work.

All 4 comments

as a workaround - add gem 'pundit' to Gemfile and it will work.

@SleeplessByte, thanks for raising this issue. Would you be able to provide specific steps to reproduce the issue so it is easier isolate the bug and fix it?

In your Gemfile (new rails project) add:

gem 'rails', '6.0.0.rc2'
gem 'administrate', '~>0.11'

Now add any administrate controller, and run rails in production mode (so that it definitely autoloads).

Given the tagged project in this issue (not mine), git checkout https://github.com/captproton/workcation_green/commit/6f1c3b12646dfea1707ca8045afdf60dbae8e8ff and running should also work as they added the workaround in the commit after this.

Another workaround for this is to not use zeitwerk, but instead the old autoloader. As per the blog post about zeitwerk integration add:

config.autoloader = :classic

to config/application.rb.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rmarronnier picture rmarronnier  路  4Comments

amyin picture amyin  路  4Comments

steffenix picture steffenix  路  4Comments

MatthiasRMS picture MatthiasRMS  路  3Comments

trandoanhung1991 picture trandoanhung1991  路  3Comments