Rails Stripe 结帐错误 - 找不到 'id'= 的插件
Rails Stripe Checkout Error - Couldn't find AddOn with 'id'=
我似乎无法理解这个错误。如何让 stripe_checkout
操作接收特定的 AddOn.find(1).price
?
add_ons_controller.rb:
def stripe_checkout
@add_on = AddOn.find(params[:id])
@amount = @add_on.price
charge = Stripe::Charge.create(
:amount => @amount * 100,
:currency => "usd",
:source => params[:stripeToken],
:description => "Test Charge"
)
flash[:notice] = "Successfully created a charge"
redirect_to '/add_ons'
end
add_ons/index.html.erb:
<% @add_ons.each do |add_on| %>
<%= add_on.title %>
<%= add_on.category %>
<%= add_on.description %>
<%= form_tag('/stripe_checkout',{method: :post}) do %>
<script class="stripe-button" data-amount="<%= add_on.price * 100 %>" data-currency="USD" data-email="customer@example.com" data-key="<%= Rails.configuration.stripe[:publishable_key] %>" src="https://checkout.stripe.com/checkout.js"></script>
<% end %>
<% end %>
您没有将 id
传递给 form_tag 助手:
<% @add_ons.each do |add_on| %>
# some code here
<%= form_tag('/stripe_checkout',{method: :post}) do %>
<%= hidden_field_tag :id, add_on.id %>
<script class="stripe-button" data-amount="<%= add_on.price * 100 %>" data-currency="USD" data-email="customer@example.com" data-key="<%= Rails.configuration.stripe[:publishable_key] %>" src="https://checkout.stripe.com/checkout.js"> </script>
<% end %>
<% end %>
我似乎无法理解这个错误。如何让 stripe_checkout
操作接收特定的 AddOn.find(1).price
?
add_ons_controller.rb:
def stripe_checkout
@add_on = AddOn.find(params[:id])
@amount = @add_on.price
charge = Stripe::Charge.create(
:amount => @amount * 100,
:currency => "usd",
:source => params[:stripeToken],
:description => "Test Charge"
)
flash[:notice] = "Successfully created a charge"
redirect_to '/add_ons'
end
add_ons/index.html.erb:
<% @add_ons.each do |add_on| %>
<%= add_on.title %>
<%= add_on.category %>
<%= add_on.description %>
<%= form_tag('/stripe_checkout',{method: :post}) do %>
<script class="stripe-button" data-amount="<%= add_on.price * 100 %>" data-currency="USD" data-email="customer@example.com" data-key="<%= Rails.configuration.stripe[:publishable_key] %>" src="https://checkout.stripe.com/checkout.js"></script>
<% end %>
<% end %>
您没有将 id
传递给 form_tag 助手:
<% @add_ons.each do |add_on| %>
# some code here
<%= form_tag('/stripe_checkout',{method: :post}) do %>
<%= hidden_field_tag :id, add_on.id %>
<script class="stripe-button" data-amount="<%= add_on.price * 100 %>" data-currency="USD" data-email="customer@example.com" data-key="<%= Rails.configuration.stripe[:publishable_key] %>" src="https://checkout.stripe.com/checkout.js"> </script>
<% end %>
<% end %>