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:
or
createmethod creates an AR object and saves it in the database.However, you cannot redirect to 10 objects.