Let me see if you understand you.
The model / entity relationship you are describing is as follows:
student address - house_name - street_name - etc phone_number - number - area_code - etc
Do you want to:
a) automatically generates models
b) automatically creates a controller / view with a form for creating a student, including fields for setting the address and phone number
Good. b) cannot be done using the Rails overpass. However, to achieve this you can use the ActiveSupport gem ( docs here ). Here is what you do:
gem install active_scaffold rails g active_scaffold Student name:string rails g active_scaffold PhoneNumber area_code:integer number:integer student_id:integer rails g active_scaffold Address first_line:string second_line:string student_id:integer
The only manual work that you will need to do is pop up into the model and add the relationship:
Address belongs_to :student PhoneNumber belongs_to :student Student has_one :address has_one :phone_number
What ActiveScaffold will do is automatically create for your view:

Fill out this form and your models will be saved and linked together!
Will hamilton
source share