错误"No route matches"错误Rails
Erroneous "No route matches" error Rails
这是我第一次整合条纹。我已将 pages#purchase 设置为我的主页。我正在使用 payments_controller 来处理条纹支付。
错误
ActionController::RoutingError (No route matches [POST] "/payments/create"):
路线
resources :payments, only: [:create]
佣金路线
payments POST /payments(.:format) payments#create
Pages/Purchase
<%= form_tag "/payments/create" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<% end %>
Shared/_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 (.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
你的form_tag
url是错误的。必须是:
<%= form_tag "/payments" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<% end %>
表格的:method
默认为POST.
这是我第一次整合条纹。我已将 pages#purchase 设置为我的主页。我正在使用 payments_controller 来处理条纹支付。 错误
ActionController::RoutingError (No route matches [POST] "/payments/create"):
路线
resources :payments, only: [:create]
佣金路线
payments POST /payments(.:format) payments#create
Pages/Purchase
<%= form_tag "/payments/create" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<% end %>
Shared/_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 (.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
你的form_tag
url是错误的。必须是:
<%= form_tag "/payments" do %>
<%= render partial: "shared/stripe_checkout_button" %>
<% end %>
表格的:method
默认为POST.