I was able to integrate stripe using Ryan Bates’ tutorial. Now, I’d like to be able to allow users to update their Credit Card Information. I’ve set up a form, at change_plan_path, which sends A PUT request to users/update_card . However, when I click the Update Credit Card Button, I get the error :
Template is missing
Missing template users/update_card, application/update_card with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Sites/dentist/app/views"
Here’s the form I’m using to send the PUT Request :
<%= form_tag("/users/update_card", :method => "put", :class => "edit_user", :id => "change_card" ) do %>
<%= hidden_field_tag :stripe_card_token %>
<div id="stripe_error" class="alert">
<noscript>JavaScript is not enabled and is required for this form. First enable it in your web browser settings.</noscript>
</div>
<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>
<%= submit_tag("Update My Credit Card", :class => "button") %>
Here’s my routes.rb file :
put '/users/update_plan', to: 'users#update_plan'
put '/users/update_card', to: 'users#update_card'
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :phones, only: [:new, :create, :destroy]
resources :find_numbers, only: [:new, :create]
match '/signup', to: 'users#new'
match '/login', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/change_plan', to: 'users#change_plan'
match '/change_card', to: 'users#change_card'
root to: 'static_pages#home'
match '/product_demo', to: 'static_pages#product_demo'
match '/pricing', to: 'plans#index'
match '/contact', to: 'static_pages#contact'
And here’s the Stripe Coffescript I’m using. It doesn’t seem to even work yet, but maybe it has something to do with it. (Start with changecard.setupForm() )
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subscription.setupForm()
subscription =
setupForm: ->
$('#new_user').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
subscription.processCard()
false
else
true
processCard: ->
card =
number: $('#card_number').val()
cvc: $('#card_code').val()
expMonth: $('#card_month').val()
expYear: $('#card_year').val()
Stripe.createToken(card, subscription.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#user_stripe_card_token').val(response.id)
$('#new_user')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
changecard.setupForm()
changecard =
setupForm: ->
$('#change_card').submit ->
$('input[type=submit]').attr('disabled', true)
if $('#card_number').length
subscription.processCard()
false
else
true
processCard: ->
card =
number: $('#card_number').val()
cvc: $('#card_code').val()
expMonth: $('#card_month').val()
expYear: $('#card_year').val()
Stripe.createToken(card, subscription.handleStripeResponse)
handleStripeResponse: (status, response) ->
if status == 200
$('#user_stripe_card_token').val(response.id)
$('#change_card')[0].submit()
else
$('#stripe_error').text(response.error.message)
$('input[type=submit]').attr('disabled', false)
Usually when you get this error it’s after the controller action has executed and it’s trying to render something back to the browser. Unless you explicitly tell it what to render, it will try and serve a view based on the controller/action. Without knowing what your controller looks like, it’s hard to say exactly what you what to happen after the info has been updated. I would expect you’d either want to redirect to a new page, or render a page.
If you want to redirect, you can do with with
redirect_toand specify the path. In the following example, I’m assuming you want to redirect to the user show action:If you want to render some content, you will need to create an html template for update_card.html.erb or render some arbitrary content like: