hkelsey-EcXoqBC4F/kd5Ot1ntKM6ZqQE7yCjDx5@public.gmane.org
2005-Oct-27 22:02 UTC
(no subject)
I''m stuck with a really basic single table inheritance question. I have a table, people with the required ''type'' column and scaffolded Person, I edited the model (person.rd) to look like this: class Person < ActiveRecord::Base end class Client < Person has_one :spouse end class Spouse < Client belongs_to :client end The controller for Person works fine but now how do I create/call the CRUD for Clients and Spouses? Also do the inherited models need to be identified somewhere in the application? Thanks. Hugh ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Thu, 2005-27-10 at 18:02 -0400, hkelsey-EcXoqBC4F/kd5Ot1ntKM6ZqQE7yCjDx5@public.gmane.org wrote:> I''m stuck with a really basic single table inheritance question. I have > a table, people with the required ''type'' column and scaffolded Person, > I edited the model (person.rd) to look like this: > > class Person < ActiveRecord::Base > end > > class Client < Person > has_one :spouse > end > > class Spouse < Client > belongs_to :client > end > > The controller for Person works fine but now how do I create/call the > CRUD for Clients and Spouses? Also do the inherited models need to be > identified somewhere in the application? Thanks. Hugh > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsHugh, I think the correct way to do this would firstly make Spouse < Person instead of Client, unless all spouses are clients. Secondly, move the declarations of the Client and Spouse models into separate files (client.rb and spouse.rb). Other than that, create a ClientController and just try it and see if it works. If it starts complaining about uninitialized constant Person then you need to tell it where to look. Either stick a line in your controller that says ''model :person'' or in client.rb "require ''Person''" As for the crud stuff, you can either keep the controllers for Client and Spouse unique (scaffolding or no), or you can inherit them from PersonController. Do note that you''ll still need to create views for ClientController even if they exist for PersonController. - Jamie