I have this def in models, checked with pry and have values arriving normally, however they do not save in the @inventory variable and below I put the class Inventory too, I wanted to know if anyone could give a help, since jah thank you. p>
MODEL TRADE
def survivor_owns_items(survivor, trade_items)
trade_items.each do |trade_item|
binding.pry
@inventory = Inventory.includes(:Survivor,:Item).where({Survivor: survivor, Item: trade_items})
if @inventory.quantity < trade_items.quantity
return false
end
end
CLASS INVENTORY
class Inventory < ApplicationRecord
belongs_to :survivor
belongs_to :item
validates :survivor, :item, presence: true
validates :survivor, uniqueness: { scope: :item }
end
JSON:
{
"trade": {
"survivor_one_id": "1",
"survivor_two_id": "2",
"survivor_two_items": [{"name": "Water", "quantity":"1"}],
"survivor_one_items": [{"name":"Medication","quantity":"2"}]
}
}