lundi 27 février 2023

NoMethodError: undefined method `pluck' for nil:NilClass

I am currently working with Ruby on Rails and I encountered a weird thing.

So, I am creating an array, then using .pluck(:client_id) on that array and I get the following error: NoMethodError: undefined method 'pluck' for nil:NilClass.

I used binding.pry to check if the array is indeed nil, but this is the result:


    49: def get_associations(records, tuples)
 => 50:   binding.pry
    51:   ClientAssociatedLocation.with_deleted.
    52:     where(client_id: records.pluck(:client_id)).
    53:     where("CONCAT_WS('-', client_id, location_id) IN (?)", tuples)
    54: end

[1] pry(#<AssociatedLocations::SourcesCreator>)> records
=> [{:id=>nil, :user_id=>nil, :client_id=>1523, :location_id=>2257, :association_type=>"manual"}]
[2] pry(#<AssociatedLocations::SourcesCreator>)> records.pluck(:client_id)
=> [1523]
[3] pry(#<AssociatedLocations::SourcesCreator>)>

As you can see, the records is clearly not nil and the pluck works. Do you have any idea of why this occurred?

Aucun commentaire:

Enregistrer un commentaire