Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zeitwerk breaks override pattern #36100

Closed
jasl opened this issue Apr 26, 2019 · 7 comments
Closed

Zeitwerk breaks override pattern #36100

jasl opened this issue Apr 26, 2019 · 7 comments

Comments

@jasl
Copy link
Contributor

jasl commented Apr 26, 2019

Steps to reproduce

Follow https://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers create an override (monkey patch) for a class

This works before 6.0.0.rc1 (including 6.0.0.beta2, 6.0.0.beta3)

Expected behavior

Class should be patched

Actual behavior

/Users/jasl/.rvm/gems/ruby-2.6.3/gems/zeitwerk-2.1.5/lib/zeitwerk/loader/callbacks.rb:15:in `on_file_autoloaded': expected file /Users/jasl/Workspaces/Ruby/cybros/app/overrides/doorkeeper/application_override.rb to define constant Doorkeeper::ApplicationOverride, but didn't (NameError)

System configuration

Rails version: 6.0.0.rc1

Ruby version: 2.6.3

@jasl
Copy link
Contributor Author

jasl commented Apr 26, 2019

@fxn could you please to give some advice?

@fxn
Copy link
Member

fxn commented Apr 26, 2019

Could you please try adding this?

# config/application.rb
load_defaults "6.0"
Rails.autoloaders.main.ignore("#{Rails.root}/app/overrides")

@jasl
Copy link
Contributor Author

jasl commented Apr 26, 2019

@fxn
Thank you, It works!
I'll send a PR to update the doc

@jasl jasl closed this as completed Apr 26, 2019
@fxn
Copy link
Member

fxn commented Apr 26, 2019

Awesome!

tavyy pushed a commit to DFE-Digital/get-help-to-retrain that referenced this issue Sep 2, 2019
Zeitwerk breaks the override pattern e.g expected file
/get-help-to-retrain/app/admin/categories.rb to define constant
Categories, but didn't (NameError), we need to ignore the
exceptions.

This approach clashes with ActiveAdmin in our case, as all related
files live under /admin but do not have the expected structure.

The fix is to ignore the files that break this expected behaviour,
by doing something like:

Rails.autoloaders.main.ignore("#{Rails.root}/app/admin")

Resource:
rails/rails#36100
tavyy pushed a commit to DFE-Digital/get-help-to-retrain that referenced this issue Sep 2, 2019
Zeitwerk breaks the override pattern e.g expected file
/get-help-to-retrain/app/admin/categories.rb to define constant
Categories, but didn't (NameError), we need to ignore the
exceptions.

This approach clashes with ActiveAdmin in our case, as all related
files live under /admin but do not have the expected structure.

The fix is to ignore the files that break this expected behaviour,
by doing something like:

Rails.autoloaders.main.ignore("#{Rails.root}/app/admin")

Resource:
rails/rails#36100
@aleksandrs-ledovskis
Copy link

I'll send a PR to update the doc

Didn't seem to happen. @fxn's suggested fix needs broader exposure as Rails.autoloaders.main.ignore isn't adequately documented anywhere else.

@jasl
Copy link
Contributor Author

jasl commented Oct 10, 2019

I'll send a PR to update the doc

Didn't seem to happen. @fxn's suggested fix needs broader exposure as Rails.autoloaders.main.ignore isn't adequately documented anywhere else.

It happened long ago, but didn't merge yet, see #36102

@aleksandrs-ledovskis
Copy link

@jasl Thanks for pointing out the link I've missed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants