Create multiple users in one form












0















I have Event model and a show page which shows the @event page and the customer registration form.



Now, my client wants a form for a different kind of event, which would have customer fields as well but labeled not customer name but parent / carer's name (similar form for a customer) and he also wants a Add player button on the bottom which would allow the parent /carer to add max 3 players. So the buisness need is that a parent registers 'players'. It should be possible to add max 3 players. I am wondering how I could go about creating 4 customers in one form. To me it sounds a bit odd, to be honest. Is this even possible? Or should I introduce Parent model and a Player model and connect them with each other. So for specific kinds of events I would create a Parent/Carer and max 3 players.



<%= simple_form_for @customer do |f| %>
...
<% end %>









share|improve this question





























    0















    I have Event model and a show page which shows the @event page and the customer registration form.



    Now, my client wants a form for a different kind of event, which would have customer fields as well but labeled not customer name but parent / carer's name (similar form for a customer) and he also wants a Add player button on the bottom which would allow the parent /carer to add max 3 players. So the buisness need is that a parent registers 'players'. It should be possible to add max 3 players. I am wondering how I could go about creating 4 customers in one form. To me it sounds a bit odd, to be honest. Is this even possible? Or should I introduce Parent model and a Player model and connect them with each other. So for specific kinds of events I would create a Parent/Carer and max 3 players.



    <%= simple_form_for @customer do |f| %>
    ...
    <% end %>









    share|improve this question



























      0












      0








      0








      I have Event model and a show page which shows the @event page and the customer registration form.



      Now, my client wants a form for a different kind of event, which would have customer fields as well but labeled not customer name but parent / carer's name (similar form for a customer) and he also wants a Add player button on the bottom which would allow the parent /carer to add max 3 players. So the buisness need is that a parent registers 'players'. It should be possible to add max 3 players. I am wondering how I could go about creating 4 customers in one form. To me it sounds a bit odd, to be honest. Is this even possible? Or should I introduce Parent model and a Player model and connect them with each other. So for specific kinds of events I would create a Parent/Carer and max 3 players.



      <%= simple_form_for @customer do |f| %>
      ...
      <% end %>









      share|improve this question
















      I have Event model and a show page which shows the @event page and the customer registration form.



      Now, my client wants a form for a different kind of event, which would have customer fields as well but labeled not customer name but parent / carer's name (similar form for a customer) and he also wants a Add player button on the bottom which would allow the parent /carer to add max 3 players. So the buisness need is that a parent registers 'players'. It should be possible to add max 3 players. I am wondering how I could go about creating 4 customers in one form. To me it sounds a bit odd, to be honest. Is this even possible? Or should I introduce Parent model and a Player model and connect them with each other. So for specific kinds of events I would create a Parent/Carer and max 3 players.



      <%= simple_form_for @customer do |f| %>
      ...
      <% end %>






      ruby-on-rails






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 21:19







      jedi

















      asked Nov 22 '18 at 20:53









      jedijedi

      577419




      577419
























          1 Answer
          1






          active

          oldest

          votes


















          1














          There is no complete details to give you an specific solution, but will guide you in the right direction to solve it with an example.



          Let's say you have your Parent model and your players model, you want to add a parent with 3 players in the same form.



          we define in your parent models that you can accept nested attributes for your players, so for example if you want to create a parent with some players, you can do something like Parent.create(params_with_players_too) and it will create the parent and create the players too, associated with that parent. of course, having in mind that the params comes in the correct way.



          Class Parent < ActiveRecord::Base
          has_many :books
          accepts_nested_attributes_for :players
          end

          Class Player < ActiveRecord::Base
          belongs_to :parent
          end


          after that, your form could be something like



          <%= form_for @parent do |f| %>
          <%= f.fields_for :players, [Player.new]*3 do |player| %>
          <%= player.text_field :name %>
          <% end %>
          <%= f.submit %>
          <% end %>


          and in your controller, you have to permit the players params too, something like this



          def create
          @parent = Parent.new(parent_params)
          if @parent.save
          ...
          end

          def parent_params
          params.require(:parent).permit(:attribute1, players_attributes: [:id, :name])
          end


          of course, you will have to understand it and adapt it to your specific case, hope that this helps you.






          share|improve this answer
























          • Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

            – jedi
            Nov 23 '18 at 5:53











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437860%2fcreate-multiple-users-in-one-form%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          There is no complete details to give you an specific solution, but will guide you in the right direction to solve it with an example.



          Let's say you have your Parent model and your players model, you want to add a parent with 3 players in the same form.



          we define in your parent models that you can accept nested attributes for your players, so for example if you want to create a parent with some players, you can do something like Parent.create(params_with_players_too) and it will create the parent and create the players too, associated with that parent. of course, having in mind that the params comes in the correct way.



          Class Parent < ActiveRecord::Base
          has_many :books
          accepts_nested_attributes_for :players
          end

          Class Player < ActiveRecord::Base
          belongs_to :parent
          end


          after that, your form could be something like



          <%= form_for @parent do |f| %>
          <%= f.fields_for :players, [Player.new]*3 do |player| %>
          <%= player.text_field :name %>
          <% end %>
          <%= f.submit %>
          <% end %>


          and in your controller, you have to permit the players params too, something like this



          def create
          @parent = Parent.new(parent_params)
          if @parent.save
          ...
          end

          def parent_params
          params.require(:parent).permit(:attribute1, players_attributes: [:id, :name])
          end


          of course, you will have to understand it and adapt it to your specific case, hope that this helps you.






          share|improve this answer
























          • Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

            – jedi
            Nov 23 '18 at 5:53
















          1














          There is no complete details to give you an specific solution, but will guide you in the right direction to solve it with an example.



          Let's say you have your Parent model and your players model, you want to add a parent with 3 players in the same form.



          we define in your parent models that you can accept nested attributes for your players, so for example if you want to create a parent with some players, you can do something like Parent.create(params_with_players_too) and it will create the parent and create the players too, associated with that parent. of course, having in mind that the params comes in the correct way.



          Class Parent < ActiveRecord::Base
          has_many :books
          accepts_nested_attributes_for :players
          end

          Class Player < ActiveRecord::Base
          belongs_to :parent
          end


          after that, your form could be something like



          <%= form_for @parent do |f| %>
          <%= f.fields_for :players, [Player.new]*3 do |player| %>
          <%= player.text_field :name %>
          <% end %>
          <%= f.submit %>
          <% end %>


          and in your controller, you have to permit the players params too, something like this



          def create
          @parent = Parent.new(parent_params)
          if @parent.save
          ...
          end

          def parent_params
          params.require(:parent).permit(:attribute1, players_attributes: [:id, :name])
          end


          of course, you will have to understand it and adapt it to your specific case, hope that this helps you.






          share|improve this answer
























          • Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

            – jedi
            Nov 23 '18 at 5:53














          1












          1








          1







          There is no complete details to give you an specific solution, but will guide you in the right direction to solve it with an example.



          Let's say you have your Parent model and your players model, you want to add a parent with 3 players in the same form.



          we define in your parent models that you can accept nested attributes for your players, so for example if you want to create a parent with some players, you can do something like Parent.create(params_with_players_too) and it will create the parent and create the players too, associated with that parent. of course, having in mind that the params comes in the correct way.



          Class Parent < ActiveRecord::Base
          has_many :books
          accepts_nested_attributes_for :players
          end

          Class Player < ActiveRecord::Base
          belongs_to :parent
          end


          after that, your form could be something like



          <%= form_for @parent do |f| %>
          <%= f.fields_for :players, [Player.new]*3 do |player| %>
          <%= player.text_field :name %>
          <% end %>
          <%= f.submit %>
          <% end %>


          and in your controller, you have to permit the players params too, something like this



          def create
          @parent = Parent.new(parent_params)
          if @parent.save
          ...
          end

          def parent_params
          params.require(:parent).permit(:attribute1, players_attributes: [:id, :name])
          end


          of course, you will have to understand it and adapt it to your specific case, hope that this helps you.






          share|improve this answer













          There is no complete details to give you an specific solution, but will guide you in the right direction to solve it with an example.



          Let's say you have your Parent model and your players model, you want to add a parent with 3 players in the same form.



          we define in your parent models that you can accept nested attributes for your players, so for example if you want to create a parent with some players, you can do something like Parent.create(params_with_players_too) and it will create the parent and create the players too, associated with that parent. of course, having in mind that the params comes in the correct way.



          Class Parent < ActiveRecord::Base
          has_many :books
          accepts_nested_attributes_for :players
          end

          Class Player < ActiveRecord::Base
          belongs_to :parent
          end


          after that, your form could be something like



          <%= form_for @parent do |f| %>
          <%= f.fields_for :players, [Player.new]*3 do |player| %>
          <%= player.text_field :name %>
          <% end %>
          <%= f.submit %>
          <% end %>


          and in your controller, you have to permit the players params too, something like this



          def create
          @parent = Parent.new(parent_params)
          if @parent.save
          ...
          end

          def parent_params
          params.require(:parent).permit(:attribute1, players_attributes: [:id, :name])
          end


          of course, you will have to understand it and adapt it to your specific case, hope that this helps you.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 1:31









          xploshioOnxploshioOn

          3,27911932




          3,27911932













          • Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

            – jedi
            Nov 23 '18 at 5:53



















          • Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

            – jedi
            Nov 23 '18 at 5:53

















          Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

          – jedi
          Nov 23 '18 at 5:53





          Yes, I thought about it. I think it is not possible to have a form for customer and nest a form for 3 other customers as well.

          – jedi
          Nov 23 '18 at 5:53




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437860%2fcreate-multiple-users-in-one-form%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]