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

Rails 6 zeitwerk autoload problem with gem #36381

Open
ShakeJ opened this issue Jun 3, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@ShakeJ
Copy link

commented Jun 3, 2019

Steps to reproduce

I did ugrade rails 5.2 to 6.0. and zeitwerk autoload and use it.
but some case is failed related gem.
(I know config.load_defaults 6.0 and config.autoloader = :classic, but I wanna use zeitwerk gem :) )

  1. Gem is not support zeitwerk autoload.
    (maybe I think almost gem is not support zitwerk autoload now)

My application use knock gem.
and run in terminal
$ bin/rails zeitwerk:check

like this,

image

  1. Override issue

Zeitwork load class when const is use.
Follow this codes,

UserTokenController.rb

class UserTokenController < Knock::AuthTokenController
  private

  def auth_params
    params.permit(:login, :password, :login_token)
  end
end

and run,
I expect run auth_params in userTokenController method (not auth_params in Knock::AuthTokenController),
but this is failed.

스크린샷 2019-06-03 오전 9 09 49

See the zeitwerk logs, autloader order is

Zeitwerk@rails.main: autoload set for UserTokenController, to be loaded from /user_token_controller.rb

Zeitwerk@rails.main: constant Knock::ApplicationController loaded from file /Users/ray/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/knock-2.1.1/app/controllers/knock/application_controller.rb

Zeitwerk@rails.main: constant Knock::AuthTokenController loaded from file /Users/ray/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/knock-2.1.1/app/controllers/knock/auth_token_controller.rb

Maybe, authTokenController is last called, and method in userTokenController can't override.

I think As a solution to the problem, all gem is load first time at once, and later application controllers load. (becuase gem is not changed in run time)

How about that? and if that correct, how to first load gem before load application controllers?
Thanks

Expected behavior

Call 'auth_params' in UserTokenController

Actual behavior

Call 'auth_params' in Knock::AuthTokenController

System configuration

Rails version: 6.0.0

Ruby version: 2.6.0

I creating a test project, and will share it when it is complete.
cc @fxn

@fxn

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

ACK! Waiting for that test project.

@fxn fxn self-assigned this Jun 6, 2019

@ShakeJ

This comment has been minimized.

Copy link
Author

commented Jun 16, 2019

So sorry for late.
This is example project
https://github.com/ShakeJ/rails6-autoloader-test
migrate and run, request post method "http://localhost:3000/auth/login" and show error logs.

I'm sorry to be late :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.