문제

I would like to save a person's information like Education, Address, etc into database tables.

If I generate Person Table(with Education) using Scaffold - id is automatically generated as primary key.

I would like to generate another table called Address for the same person using Scaffold. How can I link the id of Address table to id of Person table?

도움이 되었습니까?

해결책

You want person to have_many addresses -see the rails guide for more on associations http://guides.rubyonrails.org/association_basics.html#the-has-many-association

You can scaffold this by doing

Rails g scaffold Address person:references line1:string city:string etc

This will generate another model, Address, with a foreign key person_id to say which person it belongs to.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top