Linking two tables generated from "rails generate Scaffold" (New to Ruby on Rails) -
i save person's information education, address, etc database tables.
if generate person table(with education) using scaffold - id automatically generated primary key.
i generate table called address same person using scaffold. how can link id of address table id of person table?
you want person have_many addresses -see rails guide more on associations http://guides.rubyonrails.org/association_basics.html#the-has-many-association
you can scaffold doing
rails g scaffold address person:references line1:string city:string etc
this generate model, address, foreign key person_id person belongs to.
Comments
Post a Comment