Asked

How to easily share code between different Rails apps?

I often reuse the same code across multiple Rails apps. From simple service objects to stylesheets. Iโ€™m wondering what an easy way would be to share those across different apps?

I guess I could put them into ruby gems, but that seems convoluted? Having to build/manage the gem. Imagine I just want to quickly refine the look of the button it would require me to jump into the gemโ€™s codebase, edit it there, repackage the gem, bundle update in the other codebase. See how it looks. Repeat.

Curious to hear if anyone has found a quick workflow for this?

Could you make a repo with partials and then clone that into your project + gitignore it?

Publish gems? Git sub repos?

I think the "official" way is to build your own gems and have a private rubygems thing.

Not sure if the equivalent exists for Ruby, but in JS an easy way to do this would be a tool like Lerna. It symlinks packages together for development, and then you only build/bundle during the deploy process.

I guess the common way is gem your stuff.
However it involves a lot of work.

Git submodules could be a way to go, however I would not recommend them. Used them once and its a real pain.

I just code everything as modular as possible (with clear comments etc), so I can often copy+paste the code I need and tweak where I needed. Push everything to my Gitlab to make sure I can always go back and find it.

Sign in to answer ๐Ÿ˜ƒ