【发布时间】:2016-01-20 21:13:58
【问题描述】:
我正在使用 active_record-acts_as gem 来实现多表继承。我的场景:
class Vehicle < ActiveRecord::Base
actable
end
class Plane < ActiveRecord::Base
acts_as :Vehicle
end
class Train < ActiveRecord::Base
acts_as :Vehicle
end
每当我创建 Plane 或 Train 的实例时,都会创建相应的 Vehicle。
我正在开发一个 API,因此在列出车辆后,我将返回车辆模型中的字段。但是,当我收到 GET /Vehicles/1 时,我想退回实际车辆,无论是飞机、火车等。
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails inheritance dynamic polymorphism