Sharing models between Rails apps using gems
So I'd like to share models between two Rails apps and do not like the submodules solution (burned me in the past). I'm thinking about using gems to solve this and have this basically working:
- Create a gem using jeweler (my_models)
- Create a rails app with something in the Gemfile like:
gem 'my_models', :path => '../my_models'
so you can avoid constantly packaging the gem, etc. - Use shotgun to constantly reload all the classes (otherwise you can't really edit my_models files without restarting the server/console each time.
So a few questions:
- Shot开发者_JAVA技巧gun is slow, is there a better way in Rails to reload just that one gem each time?
- If my my_models ActiveRecord models have dependencies, I put them in my_models gems, will that cause dependency nightmares in my regular app?
- What else am I missing on why this could be a bad idea?
If you use a VCS with submodules support (like Git) you could just put models into a different repository and make it a submodule of your Rails apps. That would give you an almost effortless code sharing - Rails wouldn't even know that you are cheating.
精彩评论