0

我有一个通用Service模型,其中包含一些通用功能,包括一些将被“实际服务”覆盖的功能。

服务.rb

class Service < ActiveRecord::Base
  def get_line_items
    raise "Not Implemented"
  end
end

然后我有一个扩展模型的Service模型:

misc_service.rb

class MiscService < Service
  attr_accessible :retail_price
  def get_line_items
    return [{"Misc Service - 1" => retail_price}]
  end
end

但是,当尝试在 rails 控制台中访问 MiscService 模型时,出现错误:

:001 > service = MiscService.first
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'devdb.services' doesn't exist: SHOW FULL FIELDS FROM `services`

我可以看到这种情况正在发生,因为它是 Service 模型扩展ActiveRecord::Base,那么我可以在模型中做些什么Service来使任何模型扩展它来代替使用自己的表吗?我希望从Service模型中实现这一点,而不必在任何扩展它的模型中明确定义它。

4

1 回答 1

0

这与子类无关。您的服务表本身还没有准备好。确保您已准备好迁移文件并运行$ rake db migrate

于 2014-03-13T03:04:35.007 回答