Why am I receiving this error: ActiveRecord::AssociationTypeMismatch?











up vote
-1
down vote

favorite












Issue: I am receiving error (listed below) when i try to save form data from one controller to another.




StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ"
which is an instance of String(#47334237953540)




Question: What in my code is creating the error?



I have form input that works but I want to take some of the data from it and append it elsewhere to a separate controller.



The form is for users and stripe_account controller. I want to take the acct.id from the stripe_account and also save it in the @user table under stripe_account.



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Controller Stripe_account:



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

end

def create

@stripe_account = StripeAccount.new(stripe_account_params)
@user = User.find(params[:user_id])
@stripe_account.user_id = current_user.id
acct = Stripe::Account.create({
.....
.....
@stripe_account.acct_id = acct.id
#below is what isn't working
@user.stripe_account = acct.id

respond_to do |format|
if @stripe_account.save!
format.html { redirect_to new_bank_account_path, 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


View:



  <%= form_for ([@user, @stripe_account]) do | f | %>


Routes:



resources :users do
resources :stripe_accounts
end


but got the error: StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ" which is an instance of String(#47334237953540)



... In the Users schema, I have "stripe_account" set as a string.



I tried



acct_id = current_user.stripe_account


and other iterations of this. I am assuming the issue is in my model so i tried:
accepts_nested_attributes_for :stripe_account
but the same error appeared.










share|improve this question


















  • 1




    So what is the line @user.stripe_account = acct.id for? You already bind an user to stripe account. Also, the direct source of error is pretty obvious, if you use @user.stripe_account= method, it expect StripeAccount instance.
    – Marek Lipka
    yesterday










  • It's to store it for use later on to update, edit, pay, etc. You're right though, I'm not exactly sure I should be going this far in doing this. I have a stripe_account table and a User table separate. The Stripe account takes into account the user_id, so i know what user belongs to what stripe_account. But i also want to cross through the acct.id under the User table as well under stripe_account as my other tables/models/controllers are connected through User mostly. What do you think, is that too far?
    – uno
    yesterday










  • if you use @user.stripe_account= method, it expect StripeAccount instance --- so are you saying I should be doing something more like @user.user.stripe_account? or what?
    – uno
    yesterday










  • @user.user.stripe_account didn't work. is there a way i can save the acct.id to the current users user table?
    – uno
    yesterday















up vote
-1
down vote

favorite












Issue: I am receiving error (listed below) when i try to save form data from one controller to another.




StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ"
which is an instance of String(#47334237953540)




Question: What in my code is creating the error?



I have form input that works but I want to take some of the data from it and append it elsewhere to a separate controller.



The form is for users and stripe_account controller. I want to take the acct.id from the stripe_account and also save it in the @user table under stripe_account.



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Controller Stripe_account:



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

end

def create

@stripe_account = StripeAccount.new(stripe_account_params)
@user = User.find(params[:user_id])
@stripe_account.user_id = current_user.id
acct = Stripe::Account.create({
.....
.....
@stripe_account.acct_id = acct.id
#below is what isn't working
@user.stripe_account = acct.id

respond_to do |format|
if @stripe_account.save!
format.html { redirect_to new_bank_account_path, 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


View:



  <%= form_for ([@user, @stripe_account]) do | f | %>


Routes:



resources :users do
resources :stripe_accounts
end


but got the error: StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ" which is an instance of String(#47334237953540)



... In the Users schema, I have "stripe_account" set as a string.



I tried



acct_id = current_user.stripe_account


and other iterations of this. I am assuming the issue is in my model so i tried:
accepts_nested_attributes_for :stripe_account
but the same error appeared.










share|improve this question


















  • 1




    So what is the line @user.stripe_account = acct.id for? You already bind an user to stripe account. Also, the direct source of error is pretty obvious, if you use @user.stripe_account= method, it expect StripeAccount instance.
    – Marek Lipka
    yesterday










  • It's to store it for use later on to update, edit, pay, etc. You're right though, I'm not exactly sure I should be going this far in doing this. I have a stripe_account table and a User table separate. The Stripe account takes into account the user_id, so i know what user belongs to what stripe_account. But i also want to cross through the acct.id under the User table as well under stripe_account as my other tables/models/controllers are connected through User mostly. What do you think, is that too far?
    – uno
    yesterday










  • if you use @user.stripe_account= method, it expect StripeAccount instance --- so are you saying I should be doing something more like @user.user.stripe_account? or what?
    – uno
    yesterday










  • @user.user.stripe_account didn't work. is there a way i can save the acct.id to the current users user table?
    – uno
    yesterday













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











Issue: I am receiving error (listed below) when i try to save form data from one controller to another.




StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ"
which is an instance of String(#47334237953540)




Question: What in my code is creating the error?



I have form input that works but I want to take some of the data from it and append it elsewhere to a separate controller.



The form is for users and stripe_account controller. I want to take the acct.id from the stripe_account and also save it in the @user table under stripe_account.



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Controller Stripe_account:



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

end

def create

@stripe_account = StripeAccount.new(stripe_account_params)
@user = User.find(params[:user_id])
@stripe_account.user_id = current_user.id
acct = Stripe::Account.create({
.....
.....
@stripe_account.acct_id = acct.id
#below is what isn't working
@user.stripe_account = acct.id

respond_to do |format|
if @stripe_account.save!
format.html { redirect_to new_bank_account_path, 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


View:



  <%= form_for ([@user, @stripe_account]) do | f | %>


Routes:



resources :users do
resources :stripe_accounts
end


but got the error: StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ" which is an instance of String(#47334237953540)



... In the Users schema, I have "stripe_account" set as a string.



I tried



acct_id = current_user.stripe_account


and other iterations of this. I am assuming the issue is in my model so i tried:
accepts_nested_attributes_for :stripe_account
but the same error appeared.










share|improve this question













Issue: I am receiving error (listed below) when i try to save form data from one controller to another.




StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ"
which is an instance of String(#47334237953540)




Question: What in my code is creating the error?



I have form input that works but I want to take some of the data from it and append it elsewhere to a separate controller.



The form is for users and stripe_account controller. I want to take the acct.id from the stripe_account and also save it in the @user table under stripe_account.



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Controller Stripe_account:



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

end

def create

@stripe_account = StripeAccount.new(stripe_account_params)
@user = User.find(params[:user_id])
@stripe_account.user_id = current_user.id
acct = Stripe::Account.create({
.....
.....
@stripe_account.acct_id = acct.id
#below is what isn't working
@user.stripe_account = acct.id

respond_to do |format|
if @stripe_account.save!
format.html { redirect_to new_bank_account_path, 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


View:



  <%= form_for ([@user, @stripe_account]) do | f | %>


Routes:



resources :users do
resources :stripe_accounts
end


but got the error: StripeAccount(#473341532384680) expected, got "acct_7424613FLPIHiXZ" which is an instance of String(#47334237953540)



... In the Users schema, I have "stripe_account" set as a string.



I tried



acct_id = current_user.stripe_account


and other iterations of this. I am assuming the issue is in my model so i tried:
accepts_nested_attributes_for :stripe_account
but the same error appeared.







ruby-on-rails ruby






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









uno

428




428








  • 1




    So what is the line @user.stripe_account = acct.id for? You already bind an user to stripe account. Also, the direct source of error is pretty obvious, if you use @user.stripe_account= method, it expect StripeAccount instance.
    – Marek Lipka
    yesterday










  • It's to store it for use later on to update, edit, pay, etc. You're right though, I'm not exactly sure I should be going this far in doing this. I have a stripe_account table and a User table separate. The Stripe account takes into account the user_id, so i know what user belongs to what stripe_account. But i also want to cross through the acct.id under the User table as well under stripe_account as my other tables/models/controllers are connected through User mostly. What do you think, is that too far?
    – uno
    yesterday










  • if you use @user.stripe_account= method, it expect StripeAccount instance --- so are you saying I should be doing something more like @user.user.stripe_account? or what?
    – uno
    yesterday










  • @user.user.stripe_account didn't work. is there a way i can save the acct.id to the current users user table?
    – uno
    yesterday














  • 1




    So what is the line @user.stripe_account = acct.id for? You already bind an user to stripe account. Also, the direct source of error is pretty obvious, if you use @user.stripe_account= method, it expect StripeAccount instance.
    – Marek Lipka
    yesterday










  • It's to store it for use later on to update, edit, pay, etc. You're right though, I'm not exactly sure I should be going this far in doing this. I have a stripe_account table and a User table separate. The Stripe account takes into account the user_id, so i know what user belongs to what stripe_account. But i also want to cross through the acct.id under the User table as well under stripe_account as my other tables/models/controllers are connected through User mostly. What do you think, is that too far?
    – uno
    yesterday










  • if you use @user.stripe_account= method, it expect StripeAccount instance --- so are you saying I should be doing something more like @user.user.stripe_account? or what?
    – uno
    yesterday










  • @user.user.stripe_account didn't work. is there a way i can save the acct.id to the current users user table?
    – uno
    yesterday








1




1




So what is the line @user.stripe_account = acct.id for? You already bind an user to stripe account. Also, the direct source of error is pretty obvious, if you use @user.stripe_account= method, it expect StripeAccount instance.
– Marek Lipka
yesterday




So what is the line @user.stripe_account = acct.id for? You already bind an user to stripe account. Also, the direct source of error is pretty obvious, if you use @user.stripe_account= method, it expect StripeAccount instance.
– Marek Lipka
yesterday












It's to store it for use later on to update, edit, pay, etc. You're right though, I'm not exactly sure I should be going this far in doing this. I have a stripe_account table and a User table separate. The Stripe account takes into account the user_id, so i know what user belongs to what stripe_account. But i also want to cross through the acct.id under the User table as well under stripe_account as my other tables/models/controllers are connected through User mostly. What do you think, is that too far?
– uno
yesterday




It's to store it for use later on to update, edit, pay, etc. You're right though, I'm not exactly sure I should be going this far in doing this. I have a stripe_account table and a User table separate. The Stripe account takes into account the user_id, so i know what user belongs to what stripe_account. But i also want to cross through the acct.id under the User table as well under stripe_account as my other tables/models/controllers are connected through User mostly. What do you think, is that too far?
– uno
yesterday












if you use @user.stripe_account= method, it expect StripeAccount instance --- so are you saying I should be doing something more like @user.user.stripe_account? or what?
– uno
yesterday




if you use @user.stripe_account= method, it expect StripeAccount instance --- so are you saying I should be doing something more like @user.user.stripe_account? or what?
– uno
yesterday












@user.user.stripe_account didn't work. is there a way i can save the acct.id to the current users user table?
– uno
yesterday




@user.user.stripe_account didn't work. is there a way i can save the acct.id to the current users user table?
– uno
yesterday












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Incase anyone comes across this. I had issues recording data from form to 2 controllers tables.



This is what i did to fix it (thanks to a stackO user) @arieljuod



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

//and then saving from this://
if @stripe_account.save!
//to 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%2f53237842%2fwhy-am-i-receiving-this-error-activerecordassociationtypemismatch%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Incase anyone comes across this. I had issues recording data from form to 2 controllers tables.



    This is what i did to fix it (thanks to a stackO user) @arieljuod



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

    //and then saving from this://
    if @stripe_account.save!
    //to this://
    if @stripe_account.save! && @user.save





    share|improve this answer

























      up vote
      0
      down vote













      Incase anyone comes across this. I had issues recording data from form to 2 controllers tables.



      This is what i did to fix it (thanks to a stackO user) @arieljuod



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

      //and then saving from this://
      if @stripe_account.save!
      //to this://
      if @stripe_account.save! && @user.save





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Incase anyone comes across this. I had issues recording data from form to 2 controllers tables.



        This is what i did to fix it (thanks to a stackO user) @arieljuod



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

        //and then saving from this://
        if @stripe_account.save!
        //to this://
        if @stripe_account.save! && @user.save





        share|improve this answer












        Incase anyone comes across this. I had issues recording data from form to 2 controllers tables.



        This is what i did to fix it (thanks to a stackO user) @arieljuod



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

        //and then saving from this://
        if @stripe_account.save!
        //to this://
        if @stripe_account.save! && @user.save






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 21 hours ago









        uno

        428




        428






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237842%2fwhy-am-i-receiving-this-error-activerecordassociationtypemismatch%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ