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.
ruby-on-rails ruby
add a comment |
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.
ruby-on-rails ruby
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 expectStripeAccount
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
add a comment |
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.
ruby-on-rails ruby
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
ruby-on-rails ruby
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 expectStripeAccount
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
add a comment |
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 expectStripeAccount
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered 21 hours ago
uno
428
428
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 expectStripeAccount
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