这是我第一次整合条纹。我将页面#sourcing作为我的主页。我正在使用payments_controller来处理条带付款。 错误
ActionController::RoutingError (No route matches [POST] "/payments/create"):
路线
resources :payments, only: [:create]
Rake Routes
payments POST /payments(.:format) payments#create
页/订购
<%= form_tag "/payments/create" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<% end %>
共享/ _stripe_checkout_button
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-image="/square-image.png"
data-name="Demo Site"
data-description="2 widgets ($20.00)"
data-amount="2000">
</script>
付款控制器
def create #You want might to make actions more specific.
token = params[:stripeToken] #The token when the form is posted includes the stripe token in the url.
# Create the charge in stripes servers. This is what commits the transaction.
begin
charge = Stripe::Charge.create(
:amount => 200,
:currency => "usd",
:source => token,
:description => params[:stripeEmail]
)
rescue Stripe::CardError => e
#The card was decline because of number/ccv error, expired error, bank decline, or zip error
body = e.json_body
err = body[:error]
flash[:error] = "There was an error in processing your card: #{err[:message]}"
end
end
答案 0 :(得分:4)
您的form_tag
网址错误。必须是:
<%= form_tag "/payments" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<% end %>
表单的:method
默认为 POST 。