Im new to Rails, im trying to execute the save method within an ActionController's Create method multiple times to insert multiple values
def create
 开发者_开发百科 @pin = Pin.new(params[:pin])
  i = 1
  while i < 10
    if @pin.save
    end
  end
  redirect_to @pin
end
This works but only inserts one record there's no Contraints that enforces uniqueness of Records in my Database. Please how do i correct this?
One AR objects maps to one row. You need to create new object for each row you want added.
Something like that:
10.times do
  pin = Pin.new(params[:pin])
  pin.save
end
or
10.times do 
  Pin.create(params[:pin]
end
create method creates an AR object and saves it in the database.
However, you cannot redirect to 10 objects.
you should extend your resource with create_multiple method and send params as array, see the details here
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论