Saving parameter in my UsersController (devise) from a form in StripeAccountsController?











up vote
-2
down vote

favorite












I'm wondering on the best route to go in to accomplish what I want to do..



first, my issue is that I want to save the form input from one controller to another controllers table. but the way i have it isn't working. how do i accomplish doing so?



Right now, I am attempting to simply save the stripe account token from the stripeaccount table to the users table under stripe_account.



stripe_account.acct_id >> user.stripe_account



Here's the stripe controller:



def create



    @stripe_account = StripeAccount.new(stripe_account_params)



acct = Stripe::Account.create({
:country => "US",
:type => "custom",
legal_entity: {
first_name: stripe_account_params[:first_name].capitalize,
last_name: stripe_account_params[:last_name].capitalize,
type: stripe_account_params[:account_type],
dob: {
day: stripe_account_params[:dob_day],
month: stripe_account_params[:dob_month],
year: stripe_account_params[:dob_year]
},
address: {
line1: stripe_account_params[:address_line1],
city: stripe_account_params[:address_city],
state: stripe_account_params[:address_state],
postal_code: stripe_account_params[:address_postal]
},
ssn_last_4: stripe_account_params[:ssn_last_4]
},
tos_acceptance: {
date: Time.now.to_i,
ip: request.remote_ip
}

})

@stripe_account.acct_id = acct.id




respond_to do |format|

# @user = User.find(params[:id])

if @stripe_account.save
current_user = @user
@user.stripe_account = acct.id
format.html { redirect_to @stripe_account, notice: 'Stripe account was successfully created.' }
format.json { render :show, status: :created, location: @stripe_account }
else
format.html { render :new }
format.json { render json: @stripe_account.errors, status: :unprocessable_entity }
end
end
end


This alone doesn't worked, but i figured i would pass a hidden field in the @stripe_account form to throw the stripe account id into the users.stripe_account but that doesn't work either...
as you can see in the commented out piece of code, i tried finding by user ID as well but that brings up the error "can't find without user ID".



views:



     <%= form_for @stripe_account do | f | %>
...
<div class="col-md-4">
<div class="form-group">
<%= f.label :address_postal, "Zip" %>
<%= f.text_field :address_postal, class: "form-control input-lg", placeholder: "90210" %>
</div>
</div>
...
<div class="field">
<%= f.hidden_field :id, :value => current_user.id %>
</div>
...
<%= f.button "Create Account", class: "btn btn-primary btn-lg btn-block btn-custom", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> Creating account..."} %>


The error i receive with the current code is:



undefined method `stripe_account=' for nil:NilClass


Other than solving this issue, is this the right way to go about it and most efficient. The only other route i can think of is to create a joined table but not sure if it's a "better" or more efficient way and I'm hoping some more experienced coders can let me know which is best for this use case.



I have users signup, whether a buyer or seller, and then sellers can then add their banking information - so creating a user and stripeaccount isn't done together and i dont want it to be either (in case you're wondering why i don't just do it that way)



I would love to hear what you guys thoughts on this are. thanks for your time.



-- If you guys would like more information on my code, please feel free to let me know - but i think i got mostly everything that's important.










share|improve this question




























    up vote
    -2
    down vote

    favorite












    I'm wondering on the best route to go in to accomplish what I want to do..



    first, my issue is that I want to save the form input from one controller to another controllers table. but the way i have it isn't working. how do i accomplish doing so?



    Right now, I am attempting to simply save the stripe account token from the stripeaccount table to the users table under stripe_account.



    stripe_account.acct_id >> user.stripe_account



    Here's the stripe controller:



    def create



        @stripe_account = StripeAccount.new(stripe_account_params)



    acct = Stripe::Account.create({
    :country => "US",
    :type => "custom",
    legal_entity: {
    first_name: stripe_account_params[:first_name].capitalize,
    last_name: stripe_account_params[:last_name].capitalize,
    type: stripe_account_params[:account_type],
    dob: {
    day: stripe_account_params[:dob_day],
    month: stripe_account_params[:dob_month],
    year: stripe_account_params[:dob_year]
    },
    address: {
    line1: stripe_account_params[:address_line1],
    city: stripe_account_params[:address_city],
    state: stripe_account_params[:address_state],
    postal_code: stripe_account_params[:address_postal]
    },
    ssn_last_4: stripe_account_params[:ssn_last_4]
    },
    tos_acceptance: {
    date: Time.now.to_i,
    ip: request.remote_ip
    }

    })

    @stripe_account.acct_id = acct.id




    respond_to do |format|

    # @user = User.find(params[:id])

    if @stripe_account.save
    current_user = @user
    @user.stripe_account = acct.id
    format.html { redirect_to @stripe_account, notice: 'Stripe account was successfully created.' }
    format.json { render :show, status: :created, location: @stripe_account }
    else
    format.html { render :new }
    format.json { render json: @stripe_account.errors, status: :unprocessable_entity }
    end
    end
    end


    This alone doesn't worked, but i figured i would pass a hidden field in the @stripe_account form to throw the stripe account id into the users.stripe_account but that doesn't work either...
    as you can see in the commented out piece of code, i tried finding by user ID as well but that brings up the error "can't find without user ID".



    views:



         <%= form_for @stripe_account do | f | %>
    ...
    <div class="col-md-4">
    <div class="form-group">
    <%= f.label :address_postal, "Zip" %>
    <%= f.text_field :address_postal, class: "form-control input-lg", placeholder: "90210" %>
    </div>
    </div>
    ...
    <div class="field">
    <%= f.hidden_field :id, :value => current_user.id %>
    </div>
    ...
    <%= f.button "Create Account", class: "btn btn-primary btn-lg btn-block btn-custom", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> Creating account..."} %>


    The error i receive with the current code is:



    undefined method `stripe_account=' for nil:NilClass


    Other than solving this issue, is this the right way to go about it and most efficient. The only other route i can think of is to create a joined table but not sure if it's a "better" or more efficient way and I'm hoping some more experienced coders can let me know which is best for this use case.



    I have users signup, whether a buyer or seller, and then sellers can then add their banking information - so creating a user and stripeaccount isn't done together and i dont want it to be either (in case you're wondering why i don't just do it that way)



    I would love to hear what you guys thoughts on this are. thanks for your time.



    -- If you guys would like more information on my code, please feel free to let me know - but i think i got mostly everything that's important.










    share|improve this question


























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      I'm wondering on the best route to go in to accomplish what I want to do..



      first, my issue is that I want to save the form input from one controller to another controllers table. but the way i have it isn't working. how do i accomplish doing so?



      Right now, I am attempting to simply save the stripe account token from the stripeaccount table to the users table under stripe_account.



      stripe_account.acct_id >> user.stripe_account



      Here's the stripe controller:



      def create



          @stripe_account = StripeAccount.new(stripe_account_params)



      acct = Stripe::Account.create({
      :country => "US",
      :type => "custom",
      legal_entity: {
      first_name: stripe_account_params[:first_name].capitalize,
      last_name: stripe_account_params[:last_name].capitalize,
      type: stripe_account_params[:account_type],
      dob: {
      day: stripe_account_params[:dob_day],
      month: stripe_account_params[:dob_month],
      year: stripe_account_params[:dob_year]
      },
      address: {
      line1: stripe_account_params[:address_line1],
      city: stripe_account_params[:address_city],
      state: stripe_account_params[:address_state],
      postal_code: stripe_account_params[:address_postal]
      },
      ssn_last_4: stripe_account_params[:ssn_last_4]
      },
      tos_acceptance: {
      date: Time.now.to_i,
      ip: request.remote_ip
      }

      })

      @stripe_account.acct_id = acct.id




      respond_to do |format|

      # @user = User.find(params[:id])

      if @stripe_account.save
      current_user = @user
      @user.stripe_account = acct.id
      format.html { redirect_to @stripe_account, notice: 'Stripe account was successfully created.' }
      format.json { render :show, status: :created, location: @stripe_account }
      else
      format.html { render :new }
      format.json { render json: @stripe_account.errors, status: :unprocessable_entity }
      end
      end
      end


      This alone doesn't worked, but i figured i would pass a hidden field in the @stripe_account form to throw the stripe account id into the users.stripe_account but that doesn't work either...
      as you can see in the commented out piece of code, i tried finding by user ID as well but that brings up the error "can't find without user ID".



      views:



           <%= form_for @stripe_account do | f | %>
      ...
      <div class="col-md-4">
      <div class="form-group">
      <%= f.label :address_postal, "Zip" %>
      <%= f.text_field :address_postal, class: "form-control input-lg", placeholder: "90210" %>
      </div>
      </div>
      ...
      <div class="field">
      <%= f.hidden_field :id, :value => current_user.id %>
      </div>
      ...
      <%= f.button "Create Account", class: "btn btn-primary btn-lg btn-block btn-custom", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> Creating account..."} %>


      The error i receive with the current code is:



      undefined method `stripe_account=' for nil:NilClass


      Other than solving this issue, is this the right way to go about it and most efficient. The only other route i can think of is to create a joined table but not sure if it's a "better" or more efficient way and I'm hoping some more experienced coders can let me know which is best for this use case.



      I have users signup, whether a buyer or seller, and then sellers can then add their banking information - so creating a user and stripeaccount isn't done together and i dont want it to be either (in case you're wondering why i don't just do it that way)



      I would love to hear what you guys thoughts on this are. thanks for your time.



      -- If you guys would like more information on my code, please feel free to let me know - but i think i got mostly everything that's important.










      share|improve this question















      I'm wondering on the best route to go in to accomplish what I want to do..



      first, my issue is that I want to save the form input from one controller to another controllers table. but the way i have it isn't working. how do i accomplish doing so?



      Right now, I am attempting to simply save the stripe account token from the stripeaccount table to the users table under stripe_account.



      stripe_account.acct_id >> user.stripe_account



      Here's the stripe controller:



      def create



          @stripe_account = StripeAccount.new(stripe_account_params)



      acct = Stripe::Account.create({
      :country => "US",
      :type => "custom",
      legal_entity: {
      first_name: stripe_account_params[:first_name].capitalize,
      last_name: stripe_account_params[:last_name].capitalize,
      type: stripe_account_params[:account_type],
      dob: {
      day: stripe_account_params[:dob_day],
      month: stripe_account_params[:dob_month],
      year: stripe_account_params[:dob_year]
      },
      address: {
      line1: stripe_account_params[:address_line1],
      city: stripe_account_params[:address_city],
      state: stripe_account_params[:address_state],
      postal_code: stripe_account_params[:address_postal]
      },
      ssn_last_4: stripe_account_params[:ssn_last_4]
      },
      tos_acceptance: {
      date: Time.now.to_i,
      ip: request.remote_ip
      }

      })

      @stripe_account.acct_id = acct.id




      respond_to do |format|

      # @user = User.find(params[:id])

      if @stripe_account.save
      current_user = @user
      @user.stripe_account = acct.id
      format.html { redirect_to @stripe_account, notice: 'Stripe account was successfully created.' }
      format.json { render :show, status: :created, location: @stripe_account }
      else
      format.html { render :new }
      format.json { render json: @stripe_account.errors, status: :unprocessable_entity }
      end
      end
      end


      This alone doesn't worked, but i figured i would pass a hidden field in the @stripe_account form to throw the stripe account id into the users.stripe_account but that doesn't work either...
      as you can see in the commented out piece of code, i tried finding by user ID as well but that brings up the error "can't find without user ID".



      views:



           <%= form_for @stripe_account do | f | %>
      ...
      <div class="col-md-4">
      <div class="form-group">
      <%= f.label :address_postal, "Zip" %>
      <%= f.text_field :address_postal, class: "form-control input-lg", placeholder: "90210" %>
      </div>
      </div>
      ...
      <div class="field">
      <%= f.hidden_field :id, :value => current_user.id %>
      </div>
      ...
      <%= f.button "Create Account", class: "btn btn-primary btn-lg btn-block btn-custom", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> Creating account..."} %>


      The error i receive with the current code is:



      undefined method `stripe_account=' for nil:NilClass


      Other than solving this issue, is this the right way to go about it and most efficient. The only other route i can think of is to create a joined table but not sure if it's a "better" or more efficient way and I'm hoping some more experienced coders can let me know which is best for this use case.



      I have users signup, whether a buyer or seller, and then sellers can then add their banking information - so creating a user and stripeaccount isn't done together and i dont want it to be either (in case you're wondering why i don't just do it that way)



      I would love to hear what you guys thoughts on this are. thanks for your time.



      -- If you guys would like more information on my code, please feel free to let me know - but i think i got mostly everything that's important.







      ruby-on-rails ruby stripe-payments






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 9:02

























      asked Nov 9 at 7:49









      uno

      508




      508
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          thanks to https://stackoverflow.com/users/1430810/arieljuod the question has been answered



          This is his response to a reformatted question:



          I'm guessing you are only doing @stripe_account.save and not doing @user.save (why did you cut your method?).



          You can add a @user.save or set the belongs_to assocaition with the autosave: true option.



          I'd recommend you to change this:



          @stripe_account = StripeAccount.new(stripe_account_params)
          @user = User.find(params[:user_id])
          @stripe_account.user_id = current_user.id


          to this, though:



          @user = User.find(params[:user_id])
          @stripe_account = @user.build_stripe_account(stripe_account_params)



          Although, when i previously created this question, i wasn't as far as
          i was when i ended up reformatting this similar question later on.




          So in response to this question, they're response would be more like this:



          I'd recommend you to change this:



          @stripe_account = StripeAccount.new(stripe_account_params)


          to this, though:



          @user = User.find(params[:user_id])
          @stripe_account = @user.build_stripe_account(stripe_account_params)


          And then saving like this:



            if @stripe_account.save! && @user.save





          share|improve this answer





















            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',
            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%2f53221688%2fsaving-parameter-in-my-userscontroller-devise-from-a-form-in-stripeaccountscon%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








            up vote
            0
            down vote













            thanks to https://stackoverflow.com/users/1430810/arieljuod the question has been answered



            This is his response to a reformatted question:



            I'm guessing you are only doing @stripe_account.save and not doing @user.save (why did you cut your method?).



            You can add a @user.save or set the belongs_to assocaition with the autosave: true option.



            I'd recommend you to change this:



            @stripe_account = StripeAccount.new(stripe_account_params)
            @user = User.find(params[:user_id])
            @stripe_account.user_id = current_user.id


            to this, though:



            @user = User.find(params[:user_id])
            @stripe_account = @user.build_stripe_account(stripe_account_params)



            Although, when i previously created this question, i wasn't as far as
            i was when i ended up reformatting this similar question later on.




            So in response to this question, they're response would be more like this:



            I'd recommend you to change this:



            @stripe_account = StripeAccount.new(stripe_account_params)


            to this, though:



            @user = User.find(params[:user_id])
            @stripe_account = @user.build_stripe_account(stripe_account_params)


            And then saving like this:



              if @stripe_account.save! && @user.save





            share|improve this answer

























              up vote
              0
              down vote













              thanks to https://stackoverflow.com/users/1430810/arieljuod the question has been answered



              This is his response to a reformatted question:



              I'm guessing you are only doing @stripe_account.save and not doing @user.save (why did you cut your method?).



              You can add a @user.save or set the belongs_to assocaition with the autosave: true option.



              I'd recommend you to change this:



              @stripe_account = StripeAccount.new(stripe_account_params)
              @user = User.find(params[:user_id])
              @stripe_account.user_id = current_user.id


              to this, though:



              @user = User.find(params[:user_id])
              @stripe_account = @user.build_stripe_account(stripe_account_params)



              Although, when i previously created this question, i wasn't as far as
              i was when i ended up reformatting this similar question later on.




              So in response to this question, they're response would be more like this:



              I'd recommend you to change this:



              @stripe_account = StripeAccount.new(stripe_account_params)


              to this, though:



              @user = User.find(params[:user_id])
              @stripe_account = @user.build_stripe_account(stripe_account_params)


              And then saving like this:



                if @stripe_account.save! && @user.save





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                thanks to https://stackoverflow.com/users/1430810/arieljuod the question has been answered



                This is his response to a reformatted question:



                I'm guessing you are only doing @stripe_account.save and not doing @user.save (why did you cut your method?).



                You can add a @user.save or set the belongs_to assocaition with the autosave: true option.



                I'd recommend you to change this:



                @stripe_account = StripeAccount.new(stripe_account_params)
                @user = User.find(params[:user_id])
                @stripe_account.user_id = current_user.id


                to this, though:



                @user = User.find(params[:user_id])
                @stripe_account = @user.build_stripe_account(stripe_account_params)



                Although, when i previously created this question, i wasn't as far as
                i was when i ended up reformatting this similar question later on.




                So in response to this question, they're response would be more like this:



                I'd recommend you to change this:



                @stripe_account = StripeAccount.new(stripe_account_params)


                to this, though:



                @user = User.find(params[:user_id])
                @stripe_account = @user.build_stripe_account(stripe_account_params)


                And then saving like this:



                  if @stripe_account.save! && @user.save





                share|improve this answer












                thanks to https://stackoverflow.com/users/1430810/arieljuod the question has been answered



                This is his response to a reformatted question:



                I'm guessing you are only doing @stripe_account.save and not doing @user.save (why did you cut your method?).



                You can add a @user.save or set the belongs_to assocaition with the autosave: true option.



                I'd recommend you to change this:



                @stripe_account = StripeAccount.new(stripe_account_params)
                @user = User.find(params[:user_id])
                @stripe_account.user_id = current_user.id


                to this, though:



                @user = User.find(params[:user_id])
                @stripe_account = @user.build_stripe_account(stripe_account_params)



                Although, when i previously created this question, i wasn't as far as
                i was when i ended up reformatting this similar question later on.




                So in response to this question, they're response would be more like this:



                I'd recommend you to change this:



                @stripe_account = StripeAccount.new(stripe_account_params)


                to this, though:



                @user = User.find(params[:user_id])
                @stripe_account = @user.build_stripe_account(stripe_account_params)


                And then saving like this:



                  if @stripe_account.save! && @user.save






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 4:56









                uno

                508




                508






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221688%2fsaving-parameter-in-my-userscontroller-devise-from-a-form-in-stripeaccountscon%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

                    Coverage of Google Street View

                    Full-time equivalent

                    Surfing