Sharing models between Rails apps using gems

妖精的绣舞 提交于 2020-01-03 15:20:51

问题


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:

  1. Create a gem using jeweler (my_models)
  2. 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.
  3. 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:

  1. Shotgun is slow, is there a better way in Rails to reload just that one gem each time?
  2. If my my_models ActiveRecord models have dependencies, I put them in my_models gems, will that cause dependency nightmares in my regular app?
  3. What else am I missing on why this could be a bad idea?

回答1:


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.



来源:https://stackoverflow.com/questions/5098871/sharing-models-between-rails-apps-using-gems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!