Attaching existing order (order.email) to create an account, Devise?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















This is the scenario I would like to accomplish:




  1. User creates an order (enters email into order table).

  2. User is sent order confirmation email with link to sign up.

  3. If User decides to sign up, it will connect to the account.


What would it take to accomplish this?



I'm a bit mixed up because the Order is already created and wouldn't have a current_user for the order model to attach to the User model. How would I then have it so the order.buyer_id (which is used for the current_user of the User who creates the Order) then gets associated with the to-be-signed up User who just created the order. How could I somehow embed this information in the "sign up" link that gets sent? To somehow say "if this email signs up and is confirmed, become the buyer_id for said order"?



Also, is this good practice?



Other option:



Or should I just have a "email" and "password" field when checking out where the User field get sent ahead of the payment token so the order attaches to the current_user?



Does anyone have other ideas or what I should do?



Other than this, the only thing I'm currently doing is a simple "sign up before ordering if you want to save your orders"










share|improve this question































    1















    This is the scenario I would like to accomplish:




    1. User creates an order (enters email into order table).

    2. User is sent order confirmation email with link to sign up.

    3. If User decides to sign up, it will connect to the account.


    What would it take to accomplish this?



    I'm a bit mixed up because the Order is already created and wouldn't have a current_user for the order model to attach to the User model. How would I then have it so the order.buyer_id (which is used for the current_user of the User who creates the Order) then gets associated with the to-be-signed up User who just created the order. How could I somehow embed this information in the "sign up" link that gets sent? To somehow say "if this email signs up and is confirmed, become the buyer_id for said order"?



    Also, is this good practice?



    Other option:



    Or should I just have a "email" and "password" field when checking out where the User field get sent ahead of the payment token so the order attaches to the current_user?



    Does anyone have other ideas or what I should do?



    Other than this, the only thing I'm currently doing is a simple "sign up before ordering if you want to save your orders"










    share|improve this question



























      1












      1








      1








      This is the scenario I would like to accomplish:




      1. User creates an order (enters email into order table).

      2. User is sent order confirmation email with link to sign up.

      3. If User decides to sign up, it will connect to the account.


      What would it take to accomplish this?



      I'm a bit mixed up because the Order is already created and wouldn't have a current_user for the order model to attach to the User model. How would I then have it so the order.buyer_id (which is used for the current_user of the User who creates the Order) then gets associated with the to-be-signed up User who just created the order. How could I somehow embed this information in the "sign up" link that gets sent? To somehow say "if this email signs up and is confirmed, become the buyer_id for said order"?



      Also, is this good practice?



      Other option:



      Or should I just have a "email" and "password" field when checking out where the User field get sent ahead of the payment token so the order attaches to the current_user?



      Does anyone have other ideas or what I should do?



      Other than this, the only thing I'm currently doing is a simple "sign up before ordering if you want to save your orders"










      share|improve this question
















      This is the scenario I would like to accomplish:




      1. User creates an order (enters email into order table).

      2. User is sent order confirmation email with link to sign up.

      3. If User decides to sign up, it will connect to the account.


      What would it take to accomplish this?



      I'm a bit mixed up because the Order is already created and wouldn't have a current_user for the order model to attach to the User model. How would I then have it so the order.buyer_id (which is used for the current_user of the User who creates the Order) then gets associated with the to-be-signed up User who just created the order. How could I somehow embed this information in the "sign up" link that gets sent? To somehow say "if this email signs up and is confirmed, become the buyer_id for said order"?



      Also, is this good practice?



      Other option:



      Or should I just have a "email" and "password" field when checking out where the User field get sent ahead of the payment token so the order attaches to the current_user?



      Does anyone have other ideas or what I should do?



      Other than this, the only thing I'm currently doing is a simple "sign up before ordering if you want to save your orders"







      ruby-on-rails ruby devise






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 9:00









      ray

      3,3731829




      3,3731829










      asked Jan 3 at 6:24









      unouno

      31219




      31219
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Email is unique for each user so after user signed up and account created you can run a small query where you assign created user to orders. It can be accomplished in the model



          class User < ActiveRecord::Base
          after_create :connect_orders

          ...

          def connect_orders
          Order.where(email: self.email).updated_all(buyer_id: self.id)
          end
          end





          share|improve this answer
























          • Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

            – uno
            Jan 3 at 18:33












          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%2f54017284%2fattaching-existing-order-order-email-to-create-an-account-devise%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









          0














          Email is unique for each user so after user signed up and account created you can run a small query where you assign created user to orders. It can be accomplished in the model



          class User < ActiveRecord::Base
          after_create :connect_orders

          ...

          def connect_orders
          Order.where(email: self.email).updated_all(buyer_id: self.id)
          end
          end





          share|improve this answer
























          • Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

            – uno
            Jan 3 at 18:33
















          0














          Email is unique for each user so after user signed up and account created you can run a small query where you assign created user to orders. It can be accomplished in the model



          class User < ActiveRecord::Base
          after_create :connect_orders

          ...

          def connect_orders
          Order.where(email: self.email).updated_all(buyer_id: self.id)
          end
          end





          share|improve this answer
























          • Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

            – uno
            Jan 3 at 18:33














          0












          0








          0







          Email is unique for each user so after user signed up and account created you can run a small query where you assign created user to orders. It can be accomplished in the model



          class User < ActiveRecord::Base
          after_create :connect_orders

          ...

          def connect_orders
          Order.where(email: self.email).updated_all(buyer_id: self.id)
          end
          end





          share|improve this answer













          Email is unique for each user so after user signed up and account created you can run a small query where you assign created user to orders. It can be accomplished in the model



          class User < ActiveRecord::Base
          after_create :connect_orders

          ...

          def connect_orders
          Order.where(email: self.email).updated_all(buyer_id: self.id)
          end
          end






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 9:56









          djsmentyadjsmentya

          16211




          16211













          • Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

            – uno
            Jan 3 at 18:33



















          • Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

            – uno
            Jan 3 at 18:33

















          Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

          – uno
          Jan 3 at 18:33





          Oh wow, thank you that makes some sense. I play around with that. I also found a "guest user" devise gem as well last night. I will come back soon once I play around with this and check

          – uno
          Jan 3 at 18:33




















          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%2f54017284%2fattaching-existing-order-order-email-to-create-an-account-devise%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

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter