I have a Citation class and I want each Citation to have many Resources. A resource can be a LocalFile, Link (and maybe something like a dropbox file). Resources will share most functionality and columns. I want to use single table inheritance in the following manner.
class Resource < ActiveRecord::Base
belongs_to :citation
acts_as_list :scope => :citation
end
class LocalFile < Resource
end
class Link < Resource
end
class Citation < ActiveRecord::Base
has_many :resources, class_name: "Resource"
end
I want to be able to get a collection of resources with code something like
cites = mycite.citations
and have each object in cites have the appropriate type (LocalFile, Link etc..). Will this work? Strangely despite searching extensively I haven't been able to find an answer to this simple question.
Also, will the methods added by acts_as_list work appropriately when called on objects on the various subtypes, i.e., give move them up or down in the list on all resources for a single citation
Alternatively, is there a better way to do this? I want to have the Citation class have a collection of resources of multiple subtypes. Conceptually, each resource type is capable of representing the same content just accessed in different ways.