2013-03-01 49 views

回答

0

當你做

person.city = "London" 

Rails的認爲這是set city to the string 'London'這是不正確的。你想告訴Rails的是set the city to the record in the database with a name of 'London'。你可以這樣做(最簡單的說法)

london = City.find_by_name 'London' 
person.city = london