I have following models
Order
class Order < ApplicationRecord
has_many :items
accepts_nested_attributes_for :items
end
and Item
class Item < ApplicationRecord
belongs_to :order
end
And I have following Json to parse where an order contains multiple items
{
"location": "takeAway",
"status": "preparing",
"items": [
{
"id":2,
"name": "coffee",
"quantity": 1,
"milk": "whole",
"size": "small"
}
]
}
And I have following code my controller.
params.require(:order).permit(:location, :status, items_attributes: [:id, :name, :quantity, :milk, :size])
Why I am not able to save Order records with item records? Can someone please help?
Aucun commentaire:
Enregistrer un commentaire