Using Ruby on Rails, can a polymorphic database be created in a few steps (with polymorphic associat

Posted by Jian Lin on Stack Overflow See other posts from Stack Overflow or by Jian Lin
Published on 2010-06-15T09:16:50Z Indexed on 2010/06/15 9:22 UTC
Read the original article Hit count: 250

I thought it could be created in a few steps but it can't yet:

rails poly
cd poly

ruby script/generate scaffold animal name:string obj_type:string obj_id:integer
rake:migrate

ruby script/generate scaffold human name:string passportNumber:string
rake:migrate

ruby script/generate scaffold dog name:string registrationNumber:string
rake:migrate

and now change app/models/animal.rb to:

class Animal < ActiveRecord::Base
  belongs_to :obj, :polymorphic => true
end

and run

ruby script/server

and go to

http://localhost:3000

I thought on the server then if I create an Michael, Human, J123456 and then Woofie, Dog, L23456

then the database will have entries in the Dogs table and "Humen" or "Humans" table as well as in the Animals table? But only the Animals table has records, Dogs and "Humen" do not for some reason. Is there some steps missing?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about polymorphism