I'm getting the error:
undefined method `map' for #<String:0x000000011fe89ef8> Did you mean? tap
When trying to create a new record.
Example URL from my CSV
//cdn.shopify.com/s/files/1/0613/5349/2701/products/18_720x.jpg?v=1648711965
My schema:
t.json "images"
Importer view
<div class="importer">
<h2>Importar productos a catálogo</h2>
<%= form_tag importador_path, multipart: true do %>
<%= file_field_tag :images, multiple: true %>
<%= submit_tag "Importar", class: "btn btn-primary" %>
<% end %>
<%= @importerrors %>
</div>
Product.rb
def self.my_import(file)
CSV.foreach(file.path, headers: true) do |row|
images = "https://" + row['images']
uploader = ImagesUploader.new
uploader.download! images
output = uploader.store!(images)
finalimage = uploader.url[0]
@product = Product.create(
name: row['name'],
active: row['active'],
costprice: row['costprice'],
category_id: row['category_id'],
price: row['price'],
provider: row['provider'],
tipo: row['tipo'],
description: row['description'],
images: finalimage
)
puts @product.images
@product.save
if @product.save
puts "Saved!"
else
puts @product.errors.full_messages
end
end
end
@product = Product.new(.... , images: ["square-1.jpg"], ...)