jeudi 25 juin 2015

How to use build for adding to ActiveRecord collection

I have a model called PhoneItems which has many CallingTimes. To disable the has_many autosave functionality I had to start using the build method.

phone_queue_items.calling_times.build

so that when the edit form is closed, the calling time isn't automatically saved. Now I have the following problem. I want to be able to push a second calling_time to the PhoneItem object, however the following is not working:

phone_queue_items.calling_times << CallingTimes.build

nor phone_queue_items.calling_times.build

Is there any way to do build more than one calling time in the phone_queue_item object?

Aucun commentaire:

Enregistrer un commentaire