【发布时间】:2014-07-11 07:56:09
【问题描述】:
我正在尝试使用 Stripe 创建订阅包。 这是我到目前为止所拥有的
我的控制器方法。
def subscription_one
session[:tab] = "$1.99/Month"
@subscription = Subscription.where(user_id:current_user.id)
end
def create
@subscription = Subscription.new(params[:subscription])
if @subscription.save_with_payment
redirect_to @subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
subscription_one.html.erb
<% if @subscription.present? %>
CREDIT CARD DETAILS PRESENT
<% else %>
<form action="/membership/apply" method="POST" id="payment-form">
<article>
<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"></script>
<% end %>
在我在出现的字段中给出所有值后,当我提交时出现错误
ActionController::InvalidAuthenticityToken in MembershipController#create
有什么想法吗?
【问题讨论】:
-
手动创建表单是不好的做法,因为表单中没有
csrf-token在抬头InvalidAuthenticityToken。
标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments