【发布时间】:2018-12-03 16:56:22
【问题描述】:
我是ROR的新手,
我正在尝试使用此链接将 stripe 集成到我的 ROR 项目中: https://stripe.com/docs/checkout/rails
当我转到http://localhost:3000/charges/new 路线时,我已经按照他们的建议添加了所有内容,它给了我以下错误:
No route matches charges/new error
config/routes.rb
Rails.application.routes.draw do
mount API::Root => '/'
# Getting unmatched routes
get '*unmatched_route', to: 'application#raise_not_found'
resources :charges
end
以下是生成的路由:
charges GET /charges(.:format) charges#index
POST /charges(.:format) charges#create
new_charge GET /charges/new(.:format) charges#new
edit_charge GET /charges/:id/edit(.:format) charges#edit
charge GET /charges/:id(.:format) charges#show
PATCH /charges/:id(.:format) charges#update
PUT /charges/:id(.:format) charges#update
DELETE /charges/:id(.:format) charges#destroy
charges_controller.rb:
class ChargesController < ApplicationController
def new
end
def create
# Amount in cents
@amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to 'new_charge_path'
end
end
new.html.erb
<%= form_tag charges_path do %>
<article>
<% if flash[:error].present? %>
<div id="error_explanation">
<p><%= flash[:error] %></p>
</div>
<% end %>
<label class="amount">
<span>Amount: $5.00</span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="A month's subscription"
data-amount="500"
data-locale="auto"></script>
<% end %>
谁能帮忙,我缺少什么?提前致谢。
【问题讨论】:
-
字词
raise_not_found是否出现在您的应用中的任何位置? -
“它已经注释了定义”——好吧,这就是你的问题。为什么会被评论?取消注释。
-
您找到的那个链接,它 a) 显示了另一种方法(
raise_not_found!,而不是raise_not_found),并且 b) 似乎与问题没有任何关系。据我所知,这只是一个随机项目,恰好包含一个相似的词。我赞扬您尝试研究问题,但您需要学习找到相关信息。 :) -
@SergioTulentsev 我已取消注释并尝试使用相同的 URL localhost:3000/charges/new 现在它会将我重定向到基本 URL,即 localhost:3000。
-
我找到了
before_filter :set_cache_buster, :store_location, :authenticate_session,所以我评论了它,只是为了跳过检查,现在我收到这个错误:No route matches charges/new。
标签: ruby-on-rails ruby stripe-payments payment-gateway