Missing required param: card - ruby-on-rails

In setting up so users can create a new card on file for Stripe I am getting a Stripe::InvalidRequestError at /subscriptions/changecard. The error message is Missing required param: card and points to the line #customer.cards.create({:card => #user.subscription.stripe_card_token})
If the user has a subscription they should be able to visit /subscriptions/changecard and fill out the form which will add a new card.
Subscriptions controller:
def new
plan = Plan.find(params[:plan_id])
#subscription = plan.subscriptions.build
if params[:PayerID]
#subscription.paypal_customer_token = params[:PayerID]
#subscription.paypal_payment_token = params[:token]
#subscription.email = #subscription.paypal.checkout_details.email
end
end
def create
#subscription = Subscription.new(params[:subscription])
if #subscription.save_with_payment
redirect_to #subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
def show
#subscription = Subscription.find(params[:id])
end
def paypal_checkout
plan = Plan.find(params[:plan_id])
subscription = plan.subscriptions.build
redirect_to subscription.paypal.checkout_url(
return_url: new_subscription_url(:plan_id => plan.id),
cancel_url: root_url
)
end
def updatesubscription
#user = current_user
#customer = Stripe::Customer.retrieve(#user.subscription.stripe_customer_token)
#customer.update_subscription(:plan => "1", :prorate => true)
current_user.save!
flash.alert = 'Your subscription has been updated!'
redirect_to root_url
end
def cancelsubscription
#user = current_user
#customer = Stripe::Customer.retrieve(#user.subscription.stripe_customer_token)
#customer.cancel_subscription()
current_user.save!
flash.alert = 'Your subscription has been cancelled successfully!'
redirect_to root_url
end
def showcard
#user = current_user
Stripe::Customer.retrieve(#user.subscription.stripe_customer_token).cards.all()
end
def changecard
#user = current_user
#customer = Stripe::Customer.retrieve(#user.subscription.stripe_customer_token)
card = #customer.cards.create({
:card => #user.subscription.stripe_customer_token
})
#customer.default_card = card
#customer.save
end
end
View:
Add new Credit Card
<%= form_for #user do |f| %>
<% if #subscription.errors.any? %>
<div class="error_messages">
<h2><%= pluralize(#subscription.errors.count, "error") %> prohibited this subscription from being saved:</h2>
<ul>
<% #subscription.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :plan_id %>
<%= f.hidden_field :stripe_card_token %>
<div class="field">
<%= radio_button_tag :pay_with, :card, true %>
<%= label_tag :pay_with_card do %>
<%= image_tag "visa.png" %>
<%= image_tag "mastercard.png" %>
<%= image_tag "discover.png" %>
<%= image_tag "american_express.png" %>
<%= image_tag "jcb.png" %>
</div>
<% end %>
<div id="billing_fields">
<div class="field">
<%= f.hidden_field :user_id, :value => current_user.id %>
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<% if #subscription.payment_provided? %>
Payment has been provided. Click "Subscribe" to complete the subscription.
<% else %>
<div class="field">
<%= label_tag :card_number, "Credit Card Number" %>
<%= text_field_tag :card_number, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_code, "Security Code on Card (CVV)" %>
<%= text_field_tag :card_code, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_month, "Card Expiration" %>
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
</div>
<% end %>
<div id="stripe_error">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<div class="actions">
<%= f.submit "New Card" %>
</div>
</div>
<% end %>
Routes:
get "subscriptions/cancelsubscription"
get "subscriptions/updatesubscription"
get "subscriptions/changecard"
resources :charges
resources :subscriptions
resources :plans
get 'paypal/checkout', to: 'subscriptions#paypal_checkout'

Related

NoMethodError in Products#add , undefined method `errors' for nil:NilClass

i have no idea why this error come out, can anyone help me? thanks
It shown when i comment out the product controller( def add) there.
And also if possible is that can help me check the add.html.erb there is that my option_for_select to get all the outlets correct?
Errors show in website
Errors show in console
ActionView::Template::Error (undefined method `errors' for nil:NilClass
#virtual_path = "shared/_error_messages";object = local_assign
s[:object]; object = object;; if object.errors.any?
^^^^^^^):
1: <% if object.errors.any? %>
2: <div id="error_explanation">
3: <div class="alert alert-danger">
4: The form contains <%= pluralize(object.errors.count, "error")
%>.
app/views/shared/_error_messages.html.erb:1
app/views/products/add.html.erb:5
app/views/products/add.html.erb:4
Add.html.erb
<h1>Add to outlet</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_with(model: #product, local: true) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :quantity %>
<%= f.number_field :quantity, class: 'form-control' %>
<%= f.label :price %>
<%= f.number_field :price, class: 'form-control' %>
<%= f.label :outlet %>
<%= f.select :outlet, options_for_select(#outlets), :include_blank => true %>
<%= f.hidden_field :category_id, value: 1 %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
_error_messages.html.erb
<% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
Product Controller
class ProductsController < ApplicationController
def category
#category = Category.find(params[:id])
end
def index
#products = Product.all
end
def show
#product = Product.find(params[:id])
end
def new
#product = Product.new
#product.category_id = params[:category_id]
end
def create
#product = Product.new(product_params)
#category_id = Category.find(params[:product] [:category_id])
if #product.save
flash[:success] = "Succesful create!"
redirect_to #product
else
render 'new'
end
end
def outlet
#outlet = Outlet.find(params[:id])
end
def add
##product = Product.find(params[:id])
##outlet = Outlet.find(params[:outlet_id])
end
def update
#product = Product.find(params[:id])
#outlet = Outlet.find(params[:outlet][:name])
if #product.update(product_params)
flash[:success] = "Product updated"
redirect_to #product
else
render 'add'
end
end
private
def product_params
params.require(:product).permit(:name, :quantity, :price,
:category_id)
end
end

How do I use a hidden_field_tag to help create a valid object in Ruby on Rails?

I'm creating a prayer website with the ability to comment on a public prayer. When I try to create a comment on a prayer, it returns four errors:
Prayer must exist
User must exist
User can't be blank
Prayer can't be blank
And then every comment creation form on the page is automatically filled in with the text I put in the first comment box, and all of them have the same 4 errors on them. I tried to use the hidden_field_tag to put in the comment form for the right user id and prayer id but they aren't put into the hash for the new comment object, they are separate.
This is the debug stuff at the bottom of the page:
#<ActionController::Parameters {"authenticity_token"=>"abcdefg", "comment"=>#<ActionController::Parameters {"content"=>"Comment comment 1 2 3"} permitted: false>, "user_id"=>"1", "prayer_id"=>"301", "commit"=>"Comment", "controller"=>"comments", "action"=>"create"} permitted: false>
controllers/static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
if logged_in?
#prayer = current_user.prayers.build
#comment = current_user.comments.build
#feed_items = current_user.feed.paginate(page: params[:page])
end
end
end
controllers/comments_controller.rb
class CommentsController < ApplicationController
before_action :logged_in_user, only: [:create, :destroy]
before_action :correct_user, only: :destroy
def create
#comment = Comment.create(comment_params)
if #comment.save
flash[:success] = "Comment created!"
redirect_to root_url
else
#feed_items = current_user.feed.paginate(page: params[:page])
render 'static_pages/home', status: :unprocessable_entity
end
end
def destroy
#comment.destroy
flash[:success] = "Comment deleted"
redirect_back_or_to( root_url, status: :see_other )
end
private
def comment_params
params.require(:comment).permit(:content, :prayer_id, :user_id)
end
def correct_user
#comment = current_user.comments.find_by(id: params[:id])
redirect_to root_url, status: :see_other if #comment.nil?
end
end
models/comment.rb
class Comment < ApplicationRecord
belongs_to :prayer
belongs_to :user
default_scope -> { order( created_at: :desc) }
validates :user_id, presence: true
validates :prayer_id, presence: true
validates :content, presence: true, length: { maximum: 140 }
end
views/comments/_comment.html.erb
<li id="comment-<%= comment.id %>">
<%= link_to gravatar_for(comment.user, size: 30), comment.user %>
<span class="user"><%= link_to comment.user.name, comment.user %></span>
<span class="comment-content"><%= comment.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(comment.created_at) %> ago.
<% if current_user?(comment.user) %>
<%= link_to "delete comment", comment, data: { "turbo-method": :delete,
"turbo-confirm": "Are you sure?"} %>
<% end %>
</span>
</li>
views/prayers/_prayer.html.erb
<li id="prayer-<%= prayer.id %>">
<%= link_to gravatar_for(prayer.user, size: 50), prayer.user %>
<span class="user"><%= link_to prayer.user.name, prayer.user %></span>
<span class="content">
<%= prayer.content %>
<% if prayer.image.attached? %>
<%= image_tag prayer.image.variant(:display) %>
<% end %>
</span>
<span class="timestamp">
Posted <%= time_ago_in_words(prayer.created_at) %> ago.
<% if current_user?(prayer.user) %>
<%= link_to "delete", prayer, data: { "turbo-method": :delete,
"turbo-confirm": "Are you sure?"} %>
<% end %>
</span>
<span>
<%= render 'shared/comment_form', prayer_id: prayer.id %>
</span>
<span>
<% if prayer.comments.any? %>
<ol class="comments">
<% prayer.comments.each do |comment| %>
<%= render comment %>
<% end %>
</ol>
<% end %>
</span>
</li>
** views/shared/_comment_form.html.erb * **
<%= form_with(model: #comment) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<center>
<div class="field">
<%= f.text_area(:content, placeholder: "Comment on this prayer...") %>
</div>
<div><%= hidden_field_tag :user_id, #user.id %></div>
<div><%= hidden_field_tag :prayer_id, prayer_id %></div>
<%= f.submit "Comment", class: "btn btn-primary" %>
</center>
<% end %>
views/shared/_error_messages.html.erb
<% if object != nil && object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-danger">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
views/shared/_feed.html.erb
<% if #feed_items.any? %>
<ol class="prayers">
<%= render #feed_items %>
</ol>
<%= will_paginate #feed_items,
params: { controller: :static_pages, action: :home } %>
<% end %>
With help from Maxence, I discovered I need to use f.hidden_field versus hidden_field_tag
so I changed the views/shared/_comment_form.html.erb to the following:
<%= form_with(model: #comment) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<center>
<div class="field">
<%= f.text_area(:content, placeholder: "Comment on this prayer...") %>
</div>
<div><%= f.hidden_field :user_id, value: #user.id %></div>
<div><%= f.hidden_field :prayer_id, value: prayer_id %></div>
<%= f.submit "Comment", class: "btn btn-primary" %>
</center>
<% end %>

Undefined method 'each' for nil class in create method

I'm getting an undefined method 'each' for nil class in my create method for a join table that I have.
I've got one join table for Emotions_pins and one for casues_pins the emotions pins table works fine but I'm getting the error on causes. Here's the code
_form.html.erb for Pin
<%= form_for(#pin) do |f| %>
<%= f.hidden_field :user_id, :value => current_user.id %>
<% if #pin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#pin.errors.count, "error") %> prohibited this checkin from being saved:</h2>
<ul>
<% #pin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<h3>Hi! Thank you for choosing to check-in with your teacher! This is a great way to get help, share your feelings and concerns, and make your school a safer place to learn. </h3>
<div class="form-group">
<%= label_tag(:classroom, "Select your classroom:") %>
<%= select_tag "pin[code]", options_from_collection_for_select(Classroom.all, "code", "code", ) %>
</div>
<h4>Where?</h4>
<% #causes.each do |cause| %>
<div class="checkbox">
<ul>
<li>
<%= check_box_tag "reflection[cause_ids][]", cause.id %>
<%= label_tag(cause.name) %>
</li>
<ul>
</div>
<% end %>
<div class="form-group">
<%= image_tag 'feelings.png', class: "image" %>
<h4>How are you feeling?</h4>
</div>
<% #emotions.each do |emotion| %>
<div class="checkbox">
<%= check_box_tag "pin[emotion_ids][]", emotion.id %>
<%= label_tag(emotion.name) %>
</div>
<% end %>
<div class="form-group">
<h4> You can <strong>free write </strong> </h4>
<p> I want my teacher to know _____________________________________.</p>
<%= f.text_area :question, class: "form-control" %>
</div>
<div class="form-group">
<h4> You can write about your own actions or thoughts here.</h4>
<p>Something I did was ________________________________.</p>
<%= f.text_area :question1, class: "form-control" %>
</div>
<div class="form-group">
<h4>You can write about the actions of another person here..</h4>
<p>Something __(name)_____did was___________________________________.</p>
<%= f.text_area :question2, class: "form-control" %>
</div>
<div class="form-group">
<h4>Do you have a question for your teacher?</h4>
<p>I want to ask my teacher ______________________________________.</p>
<%= f.text_area :question3, class: "form-control" %>
</div>
<div class="form-group">
<h4>Are you thinking about <strong>doing something else</strong>? You can write about it here.</h4>
<p>Something else I might do is ______________________________________.</p>
<%= f.text_area :question4, class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit "submit", class: "btn btn-lg btn-primary" %>
</div>
<% end %>
EDIT [ ADDED pin_controller.rb]
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy]
respond_to :html s
def home
#pins = Pin.all
respond_with(#pins)
authorize #pins
end
def show
respond_with(#pin)
end
def new
#pin = Pin.new
#emotions = Emotion.all
#causes = Cause.all
#school = School.find(params[:school])
respond_with(#pin)
authorize #pin
end
def edit
end
def create
code = params[:pin][:code]
#classroom = Classroom.where('code LIKE ?', code).first
unless #classroom
flash[:error] = "Classroom code incorrect"
#emotions = Emotion.all
#causes = Cause.all
render :new
else
params[:pin][:classroom_id] = #classroom.id
#pin = Pin.new(pin_params)
#pin.save
params[:pin][:cause_ids].each do |cause_id|
#cause = Cause.find(cause_id)
#pin.causes << #cause
end
params[:pin][:emotion_ids].each do |emotion_id|
#emotion = Emotion.find(emotion_id)
#pin.emotions << #emotion
end
if #pin.save
redirect_to signout_path and return
end
respond_with(#pin)
authorize #pin
end
end
def update
#pin.update(pin_params)
respond_with(#pin)
authorize #pin
end
def destroy
#pin.destroy
respond_with(#pin)
authorize #pin
end
private
def set_pin
#pin = Pin.find(params[:id])
authorize #pin
end
def pin_params
params.require(:pin).permit(:user_id, :question, :question1, :question2,
:question3, :question4, :question5, :classroom_id, :sad,
:happy, :mad, :brave, :embarrassed, :sorry, :frustrated,
:silly, :left_out, :excited, :hurt, :jealous, :confused,
:proud, :other)
end
end
Here's the exact error I'm getting
I've so far been unable to figure out the problem. What am I missing?
Stupid error but didn't catch it until I posted the form code... Thanks for the help!!
"reflection[cause_ids][]"
should be
"pin[cause_ids][]"
Thanks again for the help:)
<h4>Where?</h4>
<% #causes.each do |cause| %>
<div class="checkbox">
<ul>
<li>
<%= check_box_tag "reflection[cause_ids][]", cause.id %>
<%= label_tag(cause.name) %>
</li>
<ul>
</div>
<% end %>

Argument Error First argument in form cannot contain nil or be empty

I am setting up a form so users can add a new Stripe credit card. I receive a First argument in form cannot contain nil or be empty on the form to <%= form_for #subscription do |f| %>
What exactly am I missing so I can have the form up and submitting to Stripe?
Subscription Controller:
def new
plan = Plan.find(params[:plan_id])
#subscription = plan.subscriptions.build
if params[:PayerID]
#subscription.paypal_customer_token = params[:PayerID]
#subscription.paypal_payment_token = params[:token]
#subscription.email = #subscription.paypal.checkout_details.email
end
end
def create
#subscription = Subscription.new(params[:subscription])
if #subscription.save_with_payment
redirect_to #subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
def show
#subscription = Subscription.find(params[:id])
end
def paypal_checkout
plan = Plan.find(params[:plan_id])
subscription = plan.subscriptions.build
redirect_to subscription.paypal.checkout_url(
return_url: new_subscription_url(:plan_id => plan.id),
cancel_url: root_url
)
end
def updatesubscription
#user = current_user
#customer = Stripe::Customer.retrieve(#user.subscription.stripe_customer_token)
#customer.update_subscription(:plan => "1", :prorate => true)
current_user.save!
flash.alert = 'Your subscription has been updated!'
redirect_to root_url
end
def cancelsubscription
#user = current_user
#customer = Stripe::Customer.retrieve(#user.subscription.stripe_customer_token)
#customer.cancel_subscription()
current_user.save!
flash.alert = 'Your subscription has been cancelled successfully!'
redirect_to root_url
end
def create_card_stripe
#user = current_user
#customer = Stripe::Customer.retrieve(#user.subscription.stripe_customer_token)
#customer.cards.create({
:card => #user.subscription.stripe_customer_token
})
#user.update_attribute(:stripe_card_id, customer.active_card.id)
if customer.save
flash.alert = "Credit card updated successfully!"
redirect_to root_url
else
flash.alert = "Error with updating card"
redirect_to root_url
end
end
end
Form:
Add new Credit Card
<%= form_for #subscription do |f| %>
<% if #subscription.errors.any? %>
<div class="error_messages">
<h2><%= pluralize(#subscription.errors.count, "error") %> prohibited this subscription from being saved:</h2>
<ul>
<% #subscription.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :plan_id %>
<%= f.hidden_field :stripe_card_token %>
<div class="field">
<%= radio_button_tag :pay_with, :card, true %>
<%= label_tag :pay_with_card do %>
<%= image_tag "visa.png" %>
<%= image_tag "mastercard.png" %>
<%= image_tag "discover.png" %>
<%= image_tag "american_express.png" %>
<%= image_tag "jcb.png" %>
</div>
<% end %>
<div id="billing_fields">
<div class="field">
<%= f.hidden_field :user_id, :value => current_user.id %>
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<% if #subscription.payment_provided? %>
Payment has been provided. Click "Subscribe" to complete the subscription.
<% else %>
<div class="field">
<%= label_tag :card_number, "Credit Card Number" %>
<%= text_field_tag :card_number, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_code, "Security Code on Card (CVV)" %>
<%= text_field_tag :card_code, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_month, "Card Expiration" %>
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
</div>
<% end %>
<div id="stripe_error">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<div class="actions">
<%= f.submit "New Card" %>
</div>
</div>
<% end %>
You are getting the error because #subscription is nil.
Set the value of #subscription in the Subscription Controller's action which renders this view.

Stripe / Rails Keeps Returning Error

I am trying to allow users to deposit money into their account in a Rails app, but I keep getting my error message: "There was a problem with your credit card."
I'm following along with this RailsCast ( http://railscasts.com/episodes/288-billing-with-stripe ), but trying to allow the user to set the amount and it also save a record of it in the corresponding model.
Here's what I have:
Model:
class Deposit < Transaction
attr_accessor :stripe_card_token
def save_with_payment
if valid?
customer = Stripe::Charge.create(amount: 10, currency: "usd", card: stripe_card_token, description: "Deposit for test#example.com")
save!
end
rescue Stripe::InvalidRequestError => e
logger.error "Stripe error while creating deposit: #{e.message}"
errors.add :base, "There was a problem with your credit card."
false
end
end
Controller:
class DepositsController < ApplicationController
before_filter :authenticate_user!
def index
#deposits = Deposit.where(user_id: current_user.id).order(created_at: :desc).all
end
def new
#deposit = Deposit.new
end
def create
#deposit = Deposit.new(deposit_params)
#deposit.user_id = current_user.id
if #deposit.save_with_payment
redirect_to #deposit, :notice => "Thank you"
else
render :new
end
end
private
def deposit_params
params.require(:deposit).permit(:amount, :stripe_card_token) #add attributes in permit
end
end
New Action:
<h1>Make a Deposit</h1>
<%= form_for(#deposit) do |f| %>
<% if #deposit.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#deposit.errors.count, "error") %> prohibited this deposit from being saved:</h2>
<ul>
<% #deposit.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :stripe_card_token %>
<div class="field">
<%= f.label :amount %><br>
<%= f.text_field :amount %>
</div>
<% if #deposit.stripe_card_token.present? %>
Credit card has been provided.
<% else %>
<div class="field">
<%= label_tag :card_number, "Credit Card Number" %>
<%= text_field_tag :card_number, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_code, "Security Code on Card (CVV)" %>
<%= text_field_tag :card_code, nil, name: nil %>
</div>
<div class="field">
<%= label_tag :card_month, "Card Expiration" %>
<%= select_month nil, {add_month_numbers: true}, {name: nil, id: "card_month"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "card_year"} %>
</div>
<% end %>
<div id="stripe_error">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<div class="actions">
<%= f.submit 'Submit', :class => 'btn btn-primary' %>
</div>
<% end %>
CoffeeScript:
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
deposit.setupForm()
deposit =
setupForm: ->
$('#new_deposit').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
deposit.processCard()
false
else
true
processCard: ->
card =
amount: $('#amount').val()
number: $('#card_number').val()
cvc: $('#card_code').val()
expMonth: $('#card_month').val()
expYear: $('#card_year').val()
Stripe.createToken(card, deposit.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#subscription_stripe_card_token').val(response.id)
$('#new_deposit')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
What am I doing wrong?
I think the likely issue is that your handleStripeResponse callback in your Coffescript file is not setting the stripe token correctly. The railscast you are following has its form inside <%= form_for #subscription do |f| %> whereas yours is <%= form_for(#deposit) do |f| %> so I think your stripe token field should be able to be accessed like this:
$('#deposit_stripe_card_token').val(response.id)
You should be able to verify this either in your console or just by inspecting the DOM directly to see what the ID is on that hidden field.

Resources