rails 3.1 中的无表模型 [英] Tableless model in rails 3.1
问题描述
看起来这个方法在 rails 3.1 中不再适用.那么,有人有可行的解决方案吗?
Looks like this method doesn't work anymore in rails 3.1. So, does someone have a working solution?
实际上,我发现了这个要点.它解决了 railscast 解决方案中 columns_hash
和 column_defaults
错误的问题,但是当我尝试编写一些代码时,我总是遇到 ActiveRecord::ConnectionNotEstablished
错误属性.
Actually, I've found this gist. It solves problems with columns_hash
and column_defaults
errors from the railscast's solution but I get ActiveRecord::ConnectionNotEstablished
error all the time when I try to write some attribute.
有什么想法吗?
推荐答案
您应该创建自己的模型类并混合您需要的 ActiveModel 部分(例如,验证).Yehuda Katz 的这篇博文 有详细信息.
You should create your own model class and mix in the parts of ActiveModel (for example, validations) that you require. This blog post from Yehuda Katz has the details.
这篇关于rails 3.1 中的无表模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!