Rails 类表继承 gem、假继承和缺失方法
我正在修改现有 Rails 应用程序的一部分以使用 Class-Table-Inheritance gem (https://github.com/brunofrank/class-table-inheritance)。一切都很好,除了我在我的超类 Person 中定义了一些实例方法,所有子类都需要能够访问这些方法。例如,full_name
(返回连接的名字和姓氏)或 cite_name
(返回第一个名字和姓氏)。由于 CTI gem 实际上并不使用 Ruby 继承(所有子类仍然从 ActiveRecord::Base 继承,并且 gem 执行了一些时髦的巫术将 ActiveRecord 字段链接在一起),因此我无法在子类中访问这些方法创建的。关于解决这个问题有什么想法吗?我对 STI 不感兴趣,但我愿意对这个特定的 CTI gem 进行分叉和破解,或者查看其他解决方案。
I'm working on modifying part of an existing Rails app to use the Class-Table-Inheritance gem (https://github.com/brunofrank/class-table-inheritance). All's well, except that I have defined some instance methods in my superclass -- Person, which all subclasses need to be able to access. For instance, full_name
, which returns the concatenated first and last names, or cite_name
, which returns the first initial and last name. Since the CTI gem doesn't actually use Ruby inheritance (all subclasses still inherit from ActiveRecord::Base, and the gem does some funky voodoo to link the ActiveRecord fields together), I can't access these methods in the subclasses I've created. Any thoughts on working around this? I'm not interested in STI, but I'm willing to either fork and hack on this particular CTI gem, or look at other solutions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试http://peterhamilton.github.com/citier,它基于CITIEsForRAILS,我分叉了它&让它经历快速发展和各种其他变化。它修复了大部分(如果不是全部)错误,并且工作起来非常简单。
try http://peterhamilton.github.com/citier, it's based on CITIEsForRAILS, I forked it & put it through rapid development and various other changes. It fixes most, if not all the bugs it had and works so simply.
就在我的脑海中,您是否看到在您的子类的迁移表中您需要有一行:
以及在您的 Model.rb 文件中
Just off the top of my head, did you see that in the migration tables of your subclasses you need to have the line:
and also in your Model.rb files
我认为全新的 CITIEsForRAILS gem(Class Inheritance & Table Inheritance EmbeddingS For RAILS,请参阅 https://github.com /altrabio/CITIEsForRAILS )正是您想要的。这个宝石扩展了 CTI、STI 和多表继承,同时保留 Ruby 类继承。
I think that the brand new CITIEsForRAILS gem (Class Inheritance & Table Inheritance EmbeddingS For RAILS, see https://github.com/altrabio/CITIEsForRAILS ) does exactly what you desire. This gem extends CTI, STI, & Multi Table Inheritance while preserving Ruby class Inheritance.