rails 3.1 中的无表模型 [英] Tableless model in rails 3.1

查看:70
本文介绍了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_hashcolumn_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆