GithubHelp home page GithubHelp logo

Comments (11)

cobafan avatar cobafan commented on August 28, 2024 1

I apologize, I found other problem.

I took a misstake dupricated select autoload path.
I appriciate your comment.

config.autoload_paths += %W(#{config.root}/app/models/)
config.autoload_paths += %W(#{config.root}/app/models/hoge)

from zeitwerk.

fxn avatar fxn commented on August 28, 2024

The Foo class is not owned by your project, apparently, but a gem defines it, and your app reopens it.

So this particular class/module cannot be autoloaded/reloaded and Zeitwerk cannot handle it.

To see what you could do, could you please share the example with actual class/module name and give a bit more of context about it? It acts as namespace too? Tell us a bit more please.

from zeitwerk.

fxn avatar fxn commented on August 28, 2024

Ah, is the gem an engine?

from zeitwerk.

cobafan avatar cobafan commented on August 28, 2024

Yes, This is engine.

from zeitwerk.

cobafan avatar cobafan commented on August 28, 2024

ex:

# vendor/bundle/ruby/2.5.0/bundler/gems/whose-gem/lib/whose-gem/engine.rb

module WhoseGem
  class Engine < ::Rails::Engine
    isolate_namespace WhoseGem
  end
end
# vendor/bundle/ruby/2.5.0/bundler/gems/whose-gem/app/models/hoge.rb

class Hoge
end
# app/models/hoge.rb

require "#{WhoseGem::Engine.root}/app/models/hoge.rb"
class Hoge
end

from zeitwerk.

fxn avatar fxn commented on August 28, 2024

The autoload paths of the application take precendence over the autoload paths of engines. That means, Rails is going to consider your foo.rb first, and disregard the one in the engine as something (not) autoloadable.

I believe the following would work:

# app/models/hoge.rb
load "#{WhoseGem::Engine.root}/app/models/hoge.rb"
class Hoge
end

It is important to use load, because when Hodge is reloaded, you want to evaluate the file in the engine again.

Can you try please?

from zeitwerk.

cobafan avatar cobafan commented on August 28, 2024

I appreciate your advice.
I try to use load tomorrow morning!

from zeitwerk.

cobafan avatar cobafan commented on August 28, 2024

I try to use load. but, not load. error is uninitialized constant error.
Is there likely another problem if not work load?

from zeitwerk.

fxn avatar fxn commented on August 28, 2024

Probably. Can you reproduce in a minimal application?

from zeitwerk.

cobafan avatar cobafan commented on August 28, 2024

I try.

from zeitwerk.

cobafan avatar cobafan commented on August 28, 2024

I tried to reproduction, but i cannot.
maybe, exists other problem?

I keep doing reproduce. but you may probably clone this issue.
I appreciate your comment.

mountable enfine gem
https://github.com/cobafan/sample_mountable_engine

minimum-RailsApplication
https://github.com/cobafan/min-app

from zeitwerk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.