【问题标题】:Rails Stripe Checkout Error - Couldn't find AddOn with 'id'=Rails Stripe Checkout 错误 - 找不到带有 'id'= 的插件
【发布时间】:2016-05-19 23:29:25
【问题描述】:

我似乎无法理解错误。如何获得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 %>

【问题讨论】:

  • 动作接收到的参数是什么?
  • 抱歉,我不明白你所说的动作接收到的参数是什么意思。
  • def add_on_params params.require(:add_on).permit(:title, :description, :benefit, :category, :price, :completed_on) end

标签: ruby-on-rails ruby stripe-payments


【解决方案1】:

您没有将 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 %>

【讨论】:

  • 现在我得到了这个错误。找不到带有 'id'={:value=>1} 的插件
猜你喜欢
  • 2015-05-27
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
  • 2014-04-21
  • 1970-01-01
  • 2021-10-08
相关资源
最近更新 更多