应用程序之间共享的模型:DataMapper Rails 其他
我有一组模型需要在多个rails3/sinatra/等应用程序之间共享。我还没有见过这样的事情,我很好奇以干燥的方式解决这个问题最有效的方法是什么?我可以为模型指定一个中心区域吗?我可以创建一个只引入我需要的模型的 gem 吗?其他人是如何处理这个问题的?我正在考虑制作一个小宝石或我还不知道的东西来处理这个问题。
我正在使用 Datamapper,但这也是构建多个 Rails/非 Rails ruby 应用程序的更普遍的问题。
I have a set of models I need to share among several rails3/sinatra/etc applications. I haven't seen anything like this yet and I'm curious what is the most effective way to go about this in a DRY manner? Can I specify a central area for models, can I create a gem that only brings in the models I need? How have other people approached this issue. I was thinking of making a smallish gem or something I don't yet know about to handle this.
I'm using Datamapper, but this is also a more general issue of structuring multiple rails/non rails ruby apps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能会发现在存储库中拥有一个包含模型和关联单元测试的子模块比创建成熟的 gem 更容易。通过这种方式,您可以从一个应用程序修补到另一个应用程序,而不必自上而下地驱动所有内容。
You might find it's easier to have a submodule in your repository that contains your models and associated unit tests than to create a full-fledged gem. This way you can patch from one app to the other instead of having to drive everything top down.
您可以为要在其他应用程序中使用的模型创建公共 API。
在 Rails 中,您应该已经拥有 REST 控制器,因此您可以在其他应用程序中使用 ActiveResource。
您可以将 ActiveResource 类打包在 gem 中,以简化事情并保持干燥。
您可以检查: http://api.rubyonrails.org/classes/ActiveResource/Base.html 一些例子。
无论您使用的是 ActiveRecord 还是 DataMapper,都没有关系。
You can create public API to models you want to use in other apps.
In rails you should already have REST controllers, so you can use ActiveResource in the other apps.
You can pack your ActiveResource classes in a gem just to simplify thing and to keep things DRY.
You can check: http://api.rubyonrails.org/classes/ActiveResource/Base.html for some examples.
And it doesn't matter if you're using ActiveRecord or DataMapper.