5

在一个相当大的项目中,我遇到了深度模型嵌套的问题。例如存在这样的模型:

class Communication::Conversation::ForProposal < Communication::Conversation::Base
  ...
end

此外,每次我们需要指定 table_name、class_name、foreign_keys 等。

您知道哪些替代方案以及您认为模型实际上应该如何命名?

4

2 回答 2

0

在最新版本的 Rails 中,您可以通过将模型放在 app/models 下的目录中来命名模型。您可以为这些模型尝试 app/models/communication/conversation。

于 2013-02-16T00:52:31.650 回答
0

您应该考虑使用 mixins。它可以帮助您按功能组织代码,从而使您的代码更清晰。以下页面很好地解释了它。

http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/

我一直在 GitHub 上查看 Rails 的一些源代码,非常干净。他们大量使用mixin。

https://github.com/rails/rails/tree/master/activemodel/lib

于 2012-05-01T17:35:59.820 回答