Reputation: 57
Given: 2 Tables, Lists, and Cars, which have many to many relations.
I want to append it with data from console. Finding and reading it from the browser works, but how can I add and append through the rails controller page?
Upvotes: 0
Views: 59
Reputation: 25
With any has_many relationship you can add a record with <<
@car.lists << @list
@list.cars << @car
Upvotes: 1
Reputation: 1440
You should use this in your cad controller:
lists = List.where(id:params[:lists])
@cars.assign_attributes({lists: lists})
Upvotes: 0