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 %>
def create_multiple params[:users].each do |user| user = User.create(user) end end
You can add validation code as per your wishes, visit here how to pass form params for multiple records http://guides.rubyonrails.org/form_helpers.html#basic-structures