I have a model called Company
that has an attachment called logo
. In my dev environment I seed 75 new companies with a logo taken from a list of placeholder logo images:
# db/seeds.rb
Company.all.each do |company|
company.logo.attach(io: logos.sample,
filename: "#{company.name.parameterize}.png")
puts company.logo.attached?
end
After this runs, I have a list of 75 true values, as expected. But then I log into the rails console and run the same loop over all companies checking for a logo:
# rails c
Company.all.each do |company|
puts company.logo.attached?
end
This returns a mix of true and false values.
Why do the companies appear to have a logo attached in the seeds but then some (a little under 50% on multiple tests) don’t have a logo in the DB? This is backed up on the dev server as well where only some companies show a logo in my views.