0
我能夠使用Ryan Bates的教程集成條紋。現在,我希望能夠允許用戶更新他們的信用卡信息。我在change_plan_path中設置了一個表單,它向用戶/ update_card發送一個PUT請求。然而,當我點擊更新信用卡按鈕,我得到的錯誤:模板丟失 - >對於PUT請求
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"
下面是我用發送PUT請求的形式:
<%= form_tag("https://stackoverflow.com/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") %>
這是我的routes.rb文件:
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'
這裏是我正在使用的條紋Coffescript。它似乎還沒有工作,但也許它與它有關。 (開始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)
不錯!感謝您的幫助Beerlington - 我以不同的行動爲行動編寫了代碼......非常天真。 –
這將做到這一點:) –