Hi @scott, do you want a default image? or do you have a particular image for every case?
If it’s the first case, then you can take two approaches:
Make an script to do it, and run it directly in rails console, like:
Company.all.each do |company|
company.update_attribute(:image, 'default_image.jpg') unless company.image
end
Put the script in the migration file, like:
def up
add_column :companies, :image, :string
Company.reset_column_information
Company.all.each do |company|
company.update_attribute(:image, 'default_image.jpg') unless company.image
end
end
If it’s the second case, then you should probably do it manually in rails console. Or you can create an script to it with a hash having the keys as the company’s name and the value to be the image name, like:
companies_images = {
'company1' => 'image1.jpg',
'company2' => 'image2.jpg'
}
Company.all.each do |company|
company.update_attribute(:image, companies_images[company.name]) unless company.image
end