1

我刚刚继承了一个项目。该项目已升级到 Rails3,并且缺少 application_model。我正在尝试实施它。我已经从它扩展了所有其他模型。问题是,由于某种原因,在尝试确定表名时,ActiveRecord 使用的是 ApplicationModel,而不是子模型,所以我得到:

表“your_db.application_models”不存在。

有什么想法吗?为什么要从应用程序模型中提取?关于如何修复的任何想法?

谢谢!

4

1 回答 1

1

显然,这是问题所在(根据我在此页面上找到的内容:rails - root model or application model):

ActiveRecord normally detects when you subclass an already subclassed ActiveRecord::Base and uses this to turn STI (single table inheritance) on.
ApplicationModel will be an actual model that is expected to have a table in your database. This can lead to problems down the line.

要解决这两个问题,您必须将 abstract_class 设置为 true 才能使 ActiveRecord 正常运行。

类 ApplicationModel < ActiveRecord::Base self.abstract_class = true end

与抽象的 ActionController 相比,abstract_class 必须设置为 true,这意味着开发人员必须知道他们不能从 ApplicationModel 中删除这一行。使用 ApplicationController,您几乎可以为所欲为。

于 2012-06-09T04:26:12.313 回答