This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U722GPJPXKC
Hello group - I’m delighted to have found you - I feel like I’ve been looking for packs
since the beginning of my journey with sizeable Rails applications and I’m very excited to try it out! I have a small design question though - forgive me if this has been covered elsewhere already - I couldn’t find it. I want to have a mixture of packs and engines (treated as packs). However, converting my first engine I’ve hit a problem. Given the following desired folder structure:
{Rails.root}
app/
...
engines/
my_engine/
app/
models/
my_domain/
private_model.rb
public/
my_domain/
models/
public_model.rb
services/
public_service.rb
lib/
my_engine.rb
my_engine/
engine.rb
I’m having difficulty selectively collapsing folders under the public
section. i.e. I want to collapse models
(as per convention) but not collapse some other folders at the same level (let’s say it’s services/
which has a Services
namespace) thus:
• MyEngine::PublicModel
• MyEngine::Services::PublicService
I have Zeitwerk::Loader.for_gem
in the my_engine.rb
folder and I’ve tried collapsing the models
folder:
loader.collapse("#{MyEngine::Engine.root}/app/public/my_engine/models")
but I can’t get past NameError: uninitialized constant MyEngine::PublicModel
If I move public_model.rb
up one level to ./engines/my_engine/app/public
then everything is fine; but I really want my public models to be in public/models
.
Moving it back to public/models
and running (from the engine’s root folder):
bundle exec rake app:zeitwerk:check
I get
expected file .../engines/my_engine/app/public/my_engine/models/public_model.rb to define constant MyEngines::Models::PublicModel
Sorry that’s a long explanation - I hoped someone might quickly recognize the issue!
Has anyone encountered something similar? Is there a trick to collapsing a app/public/models
folder from a Rails Engine? The same pattern for packs in the {Rails.root}/packs
folder does seem to work.