kdweber89 kdweber89 - 4 months ago 8
Ruby Question

Displaying specific records that match a specific criteria.

I have a number of records that I'm looping through, and i'm trying to flag out specific records that do not match the logic within my conditional. However whatever I've been trying, my results have been all of my records.

User.all.map do |u|
if [u.zip_code == true]
u.name
end
end


I feel elementary for asking this, but ultimately what i'm trying to do is flag any users that do not have a zip_code. With what I've done, is every record is displayed regardless of if I have my conditional equaling true or false.

Does anyone know what I'm doing wrong with this?

Thanks in advance.

Answer

Try

User.all.map do |u|
  if u.zip_code
    u.name
  end
end

But what if zip_code is not true?