Sharing model between rails appa

I want to split my rails app into 2 different rails app one for users and the other one for customers offering service to users.

I would like to share the models between the two apps in order to be sure that every app is always using the last version of the model objects.

Which is the best way of do that?

I was thinking about building a gem and versioning it in git and put it in the Gemfile of the 2 applications.

Your idea of building a gem that is referenced in each app is probably the best way to go. Another option is git submodules, but I don’t think there are any advantages to that.

Either way will require a fair bit of coordination between the three separate sets of code, especially if there is a lot of churn in the model code. Every time you change the model code, you’ll have to update both apps to point to the latest code and run each suite of tests. Also, you’ll have to figure out how to point your local apps at a local verison of the model code so that you can work on things locally without having to push model code to a git repo and bump your Gemfile every time you tweak something.

All things considered, personally I’d recommend a single Rails app unless you have substantial reasons for wanting to have two separate ones.

1 Like