I am developing an E-commerce application and also working on its admin website. These two applications have the same business domain and there are a few models from the e-commerce application that I need in the admin app.
I have found a few solutions online for sharing models although I am not clear which is better and how should I implement it.
Solutions I found:
Create a rake task to copy the models from the e-commerce app to the admin app
Create a third ruby module and put the models in there and pull the models from the app directory into this newly created lib and require it inside the app
Auto loading the models from the e-commerce app to admin ruby search
config.autoload_paths += %W(#{config.root}/../e-commerce-app/app/models/)
I think the second solution is the right way to do it though I am unsure of how to implement it.
None of these.
How about creating a shared gem and put that on your private git repo? With Rails, you can provide the same mechanism for autoloading the models within the application itself by packaging the gem as a rails_engine
See example
At the end require it within Gemfile
gem 'my_gem_name', git: 'http:my_git_repo.com/my_gem_name'
A more advance solution would be creating a REST service for the desired data in the e-commerce app and consume it in the admin app. Especially for Users (and authentication), it would even make sense to extract it to a separate app and provide a UserAuthentication Service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With