Why isn't my form saving but working with the API only?











up vote
0
down vote

favorite












I have my form to save to my Stripe_account table. I recently nested the resources and now the form won't save to my database tables. I have it still working with the Stripe API and working there though.



What in my code is lacking?



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Stripe_account controller:



    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])
acct = Stripe::Account.create({
.....
.....
@stripe_account.id = current_user.id
@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 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

#added for testing
get 'stripe_' => "stripe_account#create"
get 'stripe_new' => "stripe_account#new"


Here's my routes maybe can help?: https://pastebin.com/RVWd2Qq9



Now even though I don't have the "bankaccount" controller or models set up correctly yet, shouldn't it be at least attempting to go there and saving the stripe_account? Just making sure that's not the issue. But it appears it's failing because a new form reloads.



The API is successfully going through as well and the accounts are appearing within stripe, just not my own database.



What in my programming is wrong?



Update to add cmd response:



Started POST "/users/2/stripe_accounts" for 127.0.0.1 at 2018-11-10 00:11:26 -0500
Processing by StripeAccountsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nz1234567890iJuFwsm/Z4ylhE6zoGdWN6QCfWtDZTH1sxZu/WCdWMKBGkc4zoZ2dOgk9c8UDwRzgqdxrT/sA==", "stripe_account"=>{"account_type"=>"individual", "business_name"=>"", "business_tax_id"=>"", "first_name"=>"Dill", "last_name"=>"Pickles", "ssn_last_4"=>"1234", "dob_month"=>"3", "dob_day"=>"4", "dob_year"=>"1917", "address_line1"=>"198 berry avenue", "address_city"=>"san fran", "address_state"=>"CA", "address_postal"=>"90213", "tos"=>"1", "id"=>"2"}, "full_account"=>"{:value=>"true"}", "button"=>"", "user_id"=>"2"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ /home/bob/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/stripe_accounts_controller.rb:49
(0.1ms) begin transaction
↳ app/controllers/stripe_accounts_controller.rb:91
(0.1ms) rollback transaction
↳ app/controllers/stripe_accounts_controller.rb:91
Rendering stripe_accounts/new.html.erb within layouts/application
Rendered stripe_accounts/_account_form.html.erb (9.4ms)
Rendered stripe_accounts/new.html.erb within layouts/application (12.5ms)
Rendered layouts/_navbar.html.erb (1.9ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 3202ms (Views: 190.0ms | ActiveRecord: 2.4ms)









share|improve this question
























  • Can you update the question with the log that is appeared upon form submit?
    – Pavan
    Nov 10 at 4:51










  • thanks for responding. just added the log from the cmd after the form submit
    – uno
    Nov 10 at 5:15










  • You have a rollback. Try changing if @stripe_account.save to if @stripe_account.save! so it will display any validation errors if there are any.
    – Pavan
    Nov 10 at 5:20










  • now i get "(Validation failed: User must exist)" when i have "belongs_to :user" and when i have "belongs_to :users" i get (Validation failed: Users must exist)...is my model wrong?
    – uno
    Nov 10 at 5:25















up vote
0
down vote

favorite












I have my form to save to my Stripe_account table. I recently nested the resources and now the form won't save to my database tables. I have it still working with the Stripe API and working there though.



What in my code is lacking?



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Stripe_account controller:



    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])
acct = Stripe::Account.create({
.....
.....
@stripe_account.id = current_user.id
@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 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

#added for testing
get 'stripe_' => "stripe_account#create"
get 'stripe_new' => "stripe_account#new"


Here's my routes maybe can help?: https://pastebin.com/RVWd2Qq9



Now even though I don't have the "bankaccount" controller or models set up correctly yet, shouldn't it be at least attempting to go there and saving the stripe_account? Just making sure that's not the issue. But it appears it's failing because a new form reloads.



The API is successfully going through as well and the accounts are appearing within stripe, just not my own database.



What in my programming is wrong?



Update to add cmd response:



Started POST "/users/2/stripe_accounts" for 127.0.0.1 at 2018-11-10 00:11:26 -0500
Processing by StripeAccountsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nz1234567890iJuFwsm/Z4ylhE6zoGdWN6QCfWtDZTH1sxZu/WCdWMKBGkc4zoZ2dOgk9c8UDwRzgqdxrT/sA==", "stripe_account"=>{"account_type"=>"individual", "business_name"=>"", "business_tax_id"=>"", "first_name"=>"Dill", "last_name"=>"Pickles", "ssn_last_4"=>"1234", "dob_month"=>"3", "dob_day"=>"4", "dob_year"=>"1917", "address_line1"=>"198 berry avenue", "address_city"=>"san fran", "address_state"=>"CA", "address_postal"=>"90213", "tos"=>"1", "id"=>"2"}, "full_account"=>"{:value=>"true"}", "button"=>"", "user_id"=>"2"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ /home/bob/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/stripe_accounts_controller.rb:49
(0.1ms) begin transaction
↳ app/controllers/stripe_accounts_controller.rb:91
(0.1ms) rollback transaction
↳ app/controllers/stripe_accounts_controller.rb:91
Rendering stripe_accounts/new.html.erb within layouts/application
Rendered stripe_accounts/_account_form.html.erb (9.4ms)
Rendered stripe_accounts/new.html.erb within layouts/application (12.5ms)
Rendered layouts/_navbar.html.erb (1.9ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 3202ms (Views: 190.0ms | ActiveRecord: 2.4ms)









share|improve this question
























  • Can you update the question with the log that is appeared upon form submit?
    – Pavan
    Nov 10 at 4:51










  • thanks for responding. just added the log from the cmd after the form submit
    – uno
    Nov 10 at 5:15










  • You have a rollback. Try changing if @stripe_account.save to if @stripe_account.save! so it will display any validation errors if there are any.
    – Pavan
    Nov 10 at 5:20










  • now i get "(Validation failed: User must exist)" when i have "belongs_to :user" and when i have "belongs_to :users" i get (Validation failed: Users must exist)...is my model wrong?
    – uno
    Nov 10 at 5:25













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have my form to save to my Stripe_account table. I recently nested the resources and now the form won't save to my database tables. I have it still working with the Stripe API and working there though.



What in my code is lacking?



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Stripe_account controller:



    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])
acct = Stripe::Account.create({
.....
.....
@stripe_account.id = current_user.id
@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 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

#added for testing
get 'stripe_' => "stripe_account#create"
get 'stripe_new' => "stripe_account#new"


Here's my routes maybe can help?: https://pastebin.com/RVWd2Qq9



Now even though I don't have the "bankaccount" controller or models set up correctly yet, shouldn't it be at least attempting to go there and saving the stripe_account? Just making sure that's not the issue. But it appears it's failing because a new form reloads.



The API is successfully going through as well and the accounts are appearing within stripe, just not my own database.



What in my programming is wrong?



Update to add cmd response:



Started POST "/users/2/stripe_accounts" for 127.0.0.1 at 2018-11-10 00:11:26 -0500
Processing by StripeAccountsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nz1234567890iJuFwsm/Z4ylhE6zoGdWN6QCfWtDZTH1sxZu/WCdWMKBGkc4zoZ2dOgk9c8UDwRzgqdxrT/sA==", "stripe_account"=>{"account_type"=>"individual", "business_name"=>"", "business_tax_id"=>"", "first_name"=>"Dill", "last_name"=>"Pickles", "ssn_last_4"=>"1234", "dob_month"=>"3", "dob_day"=>"4", "dob_year"=>"1917", "address_line1"=>"198 berry avenue", "address_city"=>"san fran", "address_state"=>"CA", "address_postal"=>"90213", "tos"=>"1", "id"=>"2"}, "full_account"=>"{:value=>"true"}", "button"=>"", "user_id"=>"2"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ /home/bob/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/stripe_accounts_controller.rb:49
(0.1ms) begin transaction
↳ app/controllers/stripe_accounts_controller.rb:91
(0.1ms) rollback transaction
↳ app/controllers/stripe_accounts_controller.rb:91
Rendering stripe_accounts/new.html.erb within layouts/application
Rendered stripe_accounts/_account_form.html.erb (9.4ms)
Rendered stripe_accounts/new.html.erb within layouts/application (12.5ms)
Rendered layouts/_navbar.html.erb (1.9ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 3202ms (Views: 190.0ms | ActiveRecord: 2.4ms)









share|improve this question















I have my form to save to my Stripe_account table. I recently nested the resources and now the form won't save to my database tables. I have it still working with the Stripe API and working there though.



What in my code is lacking?



User Model:



  has_one :stripe_account


Stripe_account Model:



  belongs_to :users


Stripe_account controller:



    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])
acct = Stripe::Account.create({
.....
.....
@stripe_account.id = current_user.id
@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 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

#added for testing
get 'stripe_' => "stripe_account#create"
get 'stripe_new' => "stripe_account#new"


Here's my routes maybe can help?: https://pastebin.com/RVWd2Qq9



Now even though I don't have the "bankaccount" controller or models set up correctly yet, shouldn't it be at least attempting to go there and saving the stripe_account? Just making sure that's not the issue. But it appears it's failing because a new form reloads.



The API is successfully going through as well and the accounts are appearing within stripe, just not my own database.



What in my programming is wrong?



Update to add cmd response:



Started POST "/users/2/stripe_accounts" for 127.0.0.1 at 2018-11-10 00:11:26 -0500
Processing by StripeAccountsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nz1234567890iJuFwsm/Z4ylhE6zoGdWN6QCfWtDZTH1sxZu/WCdWMKBGkc4zoZ2dOgk9c8UDwRzgqdxrT/sA==", "stripe_account"=>{"account_type"=>"individual", "business_name"=>"", "business_tax_id"=>"", "first_name"=>"Dill", "last_name"=>"Pickles", "ssn_last_4"=>"1234", "dob_month"=>"3", "dob_day"=>"4", "dob_year"=>"1917", "address_line1"=>"198 berry avenue", "address_city"=>"san fran", "address_state"=>"CA", "address_postal"=>"90213", "tos"=>"1", "id"=>"2"}, "full_account"=>"{:value=>"true"}", "button"=>"", "user_id"=>"2"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ /home/bob/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
↳ app/controllers/stripe_accounts_controller.rb:49
(0.1ms) begin transaction
↳ app/controllers/stripe_accounts_controller.rb:91
(0.1ms) rollback transaction
↳ app/controllers/stripe_accounts_controller.rb:91
Rendering stripe_accounts/new.html.erb within layouts/application
Rendered stripe_accounts/_account_form.html.erb (9.4ms)
Rendered stripe_accounts/new.html.erb within layouts/application (12.5ms)
Rendered layouts/_navbar.html.erb (1.9ms)
Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 3202ms (Views: 190.0ms | ActiveRecord: 2.4ms)






ruby-on-rails ruby stripe-payments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 5:15

























asked Nov 10 at 1:37









uno

508




508












  • Can you update the question with the log that is appeared upon form submit?
    – Pavan
    Nov 10 at 4:51










  • thanks for responding. just added the log from the cmd after the form submit
    – uno
    Nov 10 at 5:15










  • You have a rollback. Try changing if @stripe_account.save to if @stripe_account.save! so it will display any validation errors if there are any.
    – Pavan
    Nov 10 at 5:20










  • now i get "(Validation failed: User must exist)" when i have "belongs_to :user" and when i have "belongs_to :users" i get (Validation failed: Users must exist)...is my model wrong?
    – uno
    Nov 10 at 5:25


















  • Can you update the question with the log that is appeared upon form submit?
    – Pavan
    Nov 10 at 4:51










  • thanks for responding. just added the log from the cmd after the form submit
    – uno
    Nov 10 at 5:15










  • You have a rollback. Try changing if @stripe_account.save to if @stripe_account.save! so it will display any validation errors if there are any.
    – Pavan
    Nov 10 at 5:20










  • now i get "(Validation failed: User must exist)" when i have "belongs_to :user" and when i have "belongs_to :users" i get (Validation failed: Users must exist)...is my model wrong?
    – uno
    Nov 10 at 5:25
















Can you update the question with the log that is appeared upon form submit?
– Pavan
Nov 10 at 4:51




Can you update the question with the log that is appeared upon form submit?
– Pavan
Nov 10 at 4:51












thanks for responding. just added the log from the cmd after the form submit
– uno
Nov 10 at 5:15




thanks for responding. just added the log from the cmd after the form submit
– uno
Nov 10 at 5:15












You have a rollback. Try changing if @stripe_account.save to if @stripe_account.save! so it will display any validation errors if there are any.
– Pavan
Nov 10 at 5:20




You have a rollback. Try changing if @stripe_account.save to if @stripe_account.save! so it will display any validation errors if there are any.
– Pavan
Nov 10 at 5:20












now i get "(Validation failed: User must exist)" when i have "belongs_to :user" and when i have "belongs_to :users" i get (Validation failed: Users must exist)...is my model wrong?
– uno
Nov 10 at 5:25




now i get "(Validation failed: User must exist)" when i have "belongs_to :user" and when i have "belongs_to :users" i get (Validation failed: Users must exist)...is my model wrong?
– uno
Nov 10 at 5:25












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











Validation failed: User must exist




You can either use optional :true to resolve the error



#stipe_account.rb
belongs_to :user, optional: true
#^ should be singular


OR



Assign the user_id in the create action like so



@stripe_account.user_id = current_user.id #add this line


Update:




undefined method `user_id=' for StripeAccount:0x001234f4c58692ae8 Did
you mean? user="




The error is because you don't have user_id column in stripe_accounts table. Generate a migration that will do the job for you



rails g migration add_user_id_to_stripe_accounts user_id:integer


and do rails db:migrate






share|improve this answer























  • So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
    – uno
    Nov 10 at 5:31










  • @uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
    – Pavan
    Nov 10 at 5:33












  • With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
    – uno
    Nov 10 at 5:36






  • 1




    @uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
    – Pavan
    Nov 10 at 5:38






  • 1




    @uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
    – Pavan
    Nov 10 at 5:43











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%2f53235289%2fwhy-isnt-my-form-saving-but-working-with-the-api-only%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
1
down vote



accepted











Validation failed: User must exist




You can either use optional :true to resolve the error



#stipe_account.rb
belongs_to :user, optional: true
#^ should be singular


OR



Assign the user_id in the create action like so



@stripe_account.user_id = current_user.id #add this line


Update:




undefined method `user_id=' for StripeAccount:0x001234f4c58692ae8 Did
you mean? user="




The error is because you don't have user_id column in stripe_accounts table. Generate a migration that will do the job for you



rails g migration add_user_id_to_stripe_accounts user_id:integer


and do rails db:migrate






share|improve this answer























  • So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
    – uno
    Nov 10 at 5:31










  • @uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
    – Pavan
    Nov 10 at 5:33












  • With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
    – uno
    Nov 10 at 5:36






  • 1




    @uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
    – Pavan
    Nov 10 at 5:38






  • 1




    @uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
    – Pavan
    Nov 10 at 5:43















up vote
1
down vote



accepted











Validation failed: User must exist




You can either use optional :true to resolve the error



#stipe_account.rb
belongs_to :user, optional: true
#^ should be singular


OR



Assign the user_id in the create action like so



@stripe_account.user_id = current_user.id #add this line


Update:




undefined method `user_id=' for StripeAccount:0x001234f4c58692ae8 Did
you mean? user="




The error is because you don't have user_id column in stripe_accounts table. Generate a migration that will do the job for you



rails g migration add_user_id_to_stripe_accounts user_id:integer


and do rails db:migrate






share|improve this answer























  • So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
    – uno
    Nov 10 at 5:31










  • @uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
    – Pavan
    Nov 10 at 5:33












  • With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
    – uno
    Nov 10 at 5:36






  • 1




    @uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
    – Pavan
    Nov 10 at 5:38






  • 1




    @uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
    – Pavan
    Nov 10 at 5:43













up vote
1
down vote



accepted







up vote
1
down vote



accepted







Validation failed: User must exist




You can either use optional :true to resolve the error



#stipe_account.rb
belongs_to :user, optional: true
#^ should be singular


OR



Assign the user_id in the create action like so



@stripe_account.user_id = current_user.id #add this line


Update:




undefined method `user_id=' for StripeAccount:0x001234f4c58692ae8 Did
you mean? user="




The error is because you don't have user_id column in stripe_accounts table. Generate a migration that will do the job for you



rails g migration add_user_id_to_stripe_accounts user_id:integer


and do rails db:migrate






share|improve this answer















Validation failed: User must exist




You can either use optional :true to resolve the error



#stipe_account.rb
belongs_to :user, optional: true
#^ should be singular


OR



Assign the user_id in the create action like so



@stripe_account.user_id = current_user.id #add this line


Update:




undefined method `user_id=' for StripeAccount:0x001234f4c58692ae8 Did
you mean? user="




The error is because you don't have user_id column in stripe_accounts table. Generate a migration that will do the job for you



rails g migration add_user_id_to_stripe_accounts user_id:integer


and do rails db:migrate







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 5:41

























answered Nov 10 at 5:29









Pavan

29.5k62952




29.5k62952












  • So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
    – uno
    Nov 10 at 5:31










  • @uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
    – Pavan
    Nov 10 at 5:33












  • With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
    – uno
    Nov 10 at 5:36






  • 1




    @uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
    – Pavan
    Nov 10 at 5:38






  • 1




    @uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
    – Pavan
    Nov 10 at 5:43


















  • So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
    – uno
    Nov 10 at 5:31










  • @uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
    – Pavan
    Nov 10 at 5:33












  • With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
    – uno
    Nov 10 at 5:36






  • 1




    @uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
    – Pavan
    Nov 10 at 5:38






  • 1




    @uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
    – Pavan
    Nov 10 at 5:43
















So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
– uno
Nov 10 at 5:31




So do both? Because i already have " @stripe_account.id = current_user.id " at the top of the create action.. is that the right spot or should it be after the stripe create section?
– uno
Nov 10 at 5:31












@uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
– Pavan
Nov 10 at 5:33






@uno @stripe_account.id = current_user.id is actually wrong! remove it from the create action. You should have @stripe_account.user_id = current_user.id instead.
– Pavan
Nov 10 at 5:33














With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
– uno
Nov 10 at 5:36




With "@stripe_account.id = current_user.id" i get this error: SQLite3::ConstraintException: UNIQUE constraint failed ... with user_id instead i get: undefined method `user_id=' for #<StripeAccount:0x001234f4c58692ae8> Did you mean? user="
– uno
Nov 10 at 5:36




1




1




@uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
– Pavan
Nov 10 at 5:38




@uno You should have user_id in the stripe_accounts table. Create a migration that will do the job for you.
– Pavan
Nov 10 at 5:38




1




1




@uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
– Pavan
Nov 10 at 5:43




@uno You should not assign any custom values to id. Its a primary key which is auto-generated in the background. BTW, check my updated answer.
– Pavan
Nov 10 at 5:43


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235289%2fwhy-isnt-my-form-saving-but-working-with-the-api-only%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

How to pass form data using jquery Ajax to insert data in database?

National Museum of Racing and Hall of Fame

Guess what letter conforming each word