jeudi 29 septembre 2022

How can I access these nested attributes in parameters?

I'm trying to get the value of one of the parameters sent, but I'm using nested attributes and when creating an object, the nested attributes have a kind of token, which prevents me from accessing the attributes through the key.

How can I access these nested attributes in parameters?

 Parameters: {"utf8"=>"✓", "authenticity_token"=>"Xodtke+W96O+hiEH8AvnK4F5XZF5U9b8148YyVTsZX5XNlkdOxmv4RTge+9MmOtfoNLOaUZbcpMcTVxRFSwRUQ==", "comanda"=>{"cliente_id"=>"1", "forma_pagamento_id"=>"1", "R$valor_total"=>"", "status"=>"false", "itens_comandas_attributes"=>{"1664413214142"=>{"produto_id"=>"1", "valor"=>"", "quantidade"=>"", "_destroy"=>"false"}, "1664413217936"=>{"produto_id"=>"2", "valor"=>"", "quantidade"=>"", "_destroy"=>"false"}}}, "commit"=>"Create Comanda"}

Here, in the nested attributes, this token "1664413214142" that contains the values, but if I try to access the "product_id" key, it doesn't return anything:

    puts params[:comanda].has_key?(:itens_comandas_attributes)

true

    puts params[:comanda][:itens_comandas_attributes]

it doesn't return anything

Aucun commentaire:

Enregistrer un commentaire