How to add a new record to a related table thru the parent table in the console?

parent table = cars
related table = parts

c = car.find_by_id(1)
c.part.new(:car_id => 1, :part_name => “gas pedal”, :color => “black”)

I can’t get this to work. How can I do this? How do I find what methods I can use for this relationship?

Hi @kimkhan, I believe you can do `c.parts.build(params)

You can read more about the methods available here

1 Like
c.parts.new(params) # will also work

The key is pluralizing parts… As @pedromoreira indicated.

1 Like

Ok. Yes, that is a good resource. Thanks for the tip.