我有「車」表看起來像這樣Ruby on Rails的,從另一個表信息插入表
ID | MAKE | MODEL
1 | acura | cl
2 | acura | el
3 | acura | integra
4 | audi | a3
... | ... | ...
,我需要從它使兩個表,「做」表中,僅以「使「來自」車輛「表的列信息並將其放入我自己成功創建的」make_name「列中(也使其不能通過uniq方法自行重複)。
id | make_name
1 | acura
2 | audi
3 | bmw
... | ...
第二個表(「make_models」),我已經做了,但有問題獲得需要的信息。表看起來像這樣
id | make_id | model_name
id | makes id to which current model belongs | model from vehicles table
我試圖插入該行軌控制檯
@vehicles = Vehicle.all
@makes = Make.all
@vehicles.each do |v|
MakeModel.create :make_id => @current_make = @makes.where(:make_name => v.make).id, :model_name => v.model
end
但得到這個錯誤消息
NoMethodError: Make Load (1.0ms) SELECT "makes".* FROM "makes" WHERE "makes"."make_name" = ? [["make_name", "ACURA"]] undefined method `id' for #
非常感謝! –