I'm developing an application to create a fishbone diagram.
I created several models to handle different levels of causes and effects. The thing is, the application will have one form to introduce data to all the different levels, so how can I do it?
Can I have only one controller to insert info into all the different tables?
Some simple inheritance will do the trick if you are going to be treating them with different logic.
Have a base model
class Bone < ActiveRecord::Base
end
Then three that inherit from it.
class BackBone < Person
end
class RibBone < Person
end
class OutSideBone < Person
end
Then you can handle all three of the classes in the person controller using person as the base. Each will also have their own logic if needed.
If need be you can even do a ownership on to itself, which might be helpful in this case.
class Bone < ActiveRecord::Base
has_many :bones
belongs_to :master_bone, :class_name => "Bone", :foreign_key => "bone_id"
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.