Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
parent table = cars related table = parts c = car.find_by_id(1) c.part.new(:car_id => 1, :part_name => "gas pedal", :color => "black")
我不能让它工作。
我怎样才能做到这一点?我如何找到可以用于这种关系的方法?
你可以这样做
c = Car.find_by_id(1) c.parts.create(:part_name => "gas pedal", :color => "black")
我假设您定义了汽车 has_many 零件关系。