0

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?

Bridge
  • 29,818
  • 9
  • 60
  • 82
  • 1
    try to add more info, but yes, of course one controller can handle as many models as you wish. – Zippie Apr 05 '13 at 21:30
  • possible duplicate of [Rails updating multiple models on a single form](http://stackoverflow.com/questions/6268861/rails-updating-multiple-models-on-a-single-form) – Mark Thomas Apr 05 '13 at 21:33

1 Answers1

1

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 
rovermicrover
  • 1,453
  • 1
  • 15
  • 21