try to do something like:
<%= form_tag(some_url_path, method: :put) do %> <% for user in @users %> <%= fields_for "users[]", user do |f| %> <%= render 'fields', f: f, user: user %> <% end %> <% end %> <%= submit_tag "Submit" %> <% end %>
and in the controller you must create @users instead of one @user method in new , and in the create method accept multiple users instead of one.
UPDATE:
when you want to update your users in the controller, you can do (as I have not tested it):
User.update(params[:users].keys, params[:users].values)
and create:
User.create(params[:users].values)
params[:users].keys should be a hash of user identifiers, and params[:users].values should be a hash of attributes of the corresponding users
I donβt know how you plan to manage the dynamic number of users, but maybe this can help.
source share