This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U7374XD6T52
anyone here using packs-rails to define routes inside the package? I’m attempting to do what’s spelled out in the readme, but I’m getting a zeitwerk error because my routes file (packs/components/config/routes/components.rb) doesn’t define a Components constant
Hi <@U7374XD6T52>, we do and have no issues, but the structure is sligthly different.
We tread each component as a mini Rails app, meaning that we put routes in components/<name>/config/routes.rb
Ah, I see there’s now a draw helper, we don’t use that and we’ve written our own instead.
Still, the docs gives this as an example:
# packs/my_domain/config/routes/my_domain.rb
Rails.application.routes.draw do
resources :my_resource
end
# config/routes.rb
Rails.application.routes.draw do
draw(:my_domain)
end
So your path above seems slightly off, it should be something like (replace pack_name) packs/pack_name/config/routes/pack_name.rb
Then, you should add the following to your root config/routes.rb file (again, replace pack_name):
hmm. that’s what I think I’m doing - my pack name is components (referring to hardware related to installing rooftop solar), so packs/components/config/routes/components.rb should be correct
(we are trying to move away from engines for our packs - we don’t want to maintain separate gemspecs everywhere if we can help it)
the only way I have been able to get zeitwerk to behave is to define an empty Components module above Rails.application.routes.draw do
it feels like it should be a clue that this breaks the functional tests for the controller, but the app is functional (including the controller in this pack) without defining Components
mmmh that’s interesting, it may be due to some meta-programming magic packs-rails does internally.
If it helps, here is what we do in our root config/routes.rb instead of calling draw :
Dir[Rails.root.join('packs/*/config/routes.rb')].each do |file_path|
instance_eval(File.read(file_path))
end
It doesn’t let you mount packs in specific places, but it does work fine with Zeitwerk.
Still worth opening an issue though, you’re following the documentation and it doesn’t work, so it may be a bug