Need Help with Modularizing Namespaces in Rails and Handling Edge Cases

This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.

While attempting to modularize via namespaces, I found it frustrating attending to various edge cases — mostly relation names and Rails not figuring out what the name should be.

Any good references on how best to approach namespaces in rails just in case I missed it and I’m making my life harder than necessary?

Message originally sent by slack user U70VMMV37TJ

I’d love to have an example of what you were struggling with.

Here’s a path example for making it easier for zeitwerk to find the files:

/packs/payments/app/controllers/payments/payment_controller.rb
/packs/payments/app/models/payments/payment.rb

If you are talking about active record relations, an example would help me.

It wasn’t with packs! Shopify, I believe, recommended starting refactoring to namespaces (in some cases).

I’ll have to look closer at what packs provide. Thanks!

Message excluded from import.

Message originally sent by slack user U717FXJ8HWK

For now at least, we don’t namespace any of the ActiveRecord models, otherwise you would have to override table names and association classes. I think namespacing makes more sense for domain code, and models can stay as is for now.

Message originally sent by slack user U70TIGAX94P

Shopify, I believe, recommended starting refactoring to namespaces
I’d like to see a source for that - in fact, during my time there we did the opposite. Moving files around is easy, renaming things is considerably harder. So no namespaces is better at the beginning when you have to expect to still move boundaries around a lot.

Namespaces can be introduced when certainty increases.

It’s sort of hearsay (or heresy…) It was a summary from someone else that was either wrong or I misunderstood.