insert multiple records to a single table from a single form

Generally if we can create only 1 record, say 1 user at a time from the form. But what if I want to create multiple users from a single form? There are no associations with other models. How can i do that?


You have to make a form with an array of users params .e.g

<%= from_tag '/users/create_multiple' do %>
 <%= text_field_tag "users[][name]" %>
 <%= text_field_tag "users[][name]" %>
<% end %>

In UsersController:

def create_multiple
 params[:users].each do |user|
  user = User.create(user)

You can add validation code as per your wishes, visit here how to pass form params for multiple records

Need Your Help

Visual Basic C# windows form background worker object movement loop not functioning as intended

c# winforms visual-studio-2012 backgroundworker

I'm currently attempting to write a classic snake sort of game, where the user directs the snake around the screen using the keyboard's arrow keys. So far, i've managed to sort out the code that di...

How To Add Media To MediaStore on Android 4.4 KitKat SD Card With Metadata

android android-sdcard android-4.4-kitkat music-player android-mediascanner

Background: In Android 4.4, Google decided that apps should not have write access to SD cards.