Q:

generate multiple record according to the number of elements of array

I would like to write code that repeats as many times as array and then store data  to the database. I think this is to go well but didn't.
Is there something wrong?
Thanks.
def create
  product = Product.new
  product_params['type'].each do |t|
    product.name = product_params['name']
    product.about = product_params['about']
    product.type = t
    product.save    
  end
end

params.require(:product).permit(:name,:about, type: [])

A:

Product instance needs to be initialized in the each iteration so that each time you will create a new record in the database instead of updating existing one:
def create
  product_params['type'].each do |t|
    Product.create(
      name: product_params['name'],
      about: product_params['about'],
      type: t
    )   
  end
end

