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.
ruby-on-rails ruby stripe-payments
add a comment |
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.
ruby-on-rails ruby stripe-payments
add a comment |
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.
ruby-on-rails ruby stripe-payments
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
ruby-on-rails ruby stripe-payments
edited Nov 9 at 9:02
asked Nov 9 at 7:49
uno
508
508
add a comment |
add a comment |
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
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
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
add a comment |
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
add a comment |
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
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
answered Nov 11 at 4:56
uno
508
508
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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