【问题标题】:Price amount not showing in Stripe Payments modal or RoR applicationStripe Payments 模式或 RoR 应用程序中未显示价格金额
【发布时间】:2016-06-21 04:24:33
【问题描述】:

我正在尝试将条带付款合并到我的 RoR 应用程序的 pin 模型中,但无济于事。 Basically, the price does not show ( in index.html.erb) and the same price amount does not appear in the stripe payments modal when selected to enter test credentials for payment processing (amount: '')。

当我创建一个新图钉并包含图片、描述等和价格时,生成的图钉会显示除价格之外的所有输入信息。这是由于某种原因它没有将此信息注册到价格列的地方。当我运行 rails console the price: is "nil" 尽管输入了一个。我不确定为什么。因此,在创建新图钉并输入价格值后,这两个区域都会显示为空白。

我在命令行中添加了一个新的迁移到名为 price 的引脚:

rails generate migration AddPriceToPins price:decimal

这是 app/db/migrate 之后的样子:

class AddPriceToPins < ActiveRecord::Migration
   def change
    add_column :pins, :price, :decimal
   end
end

接下来,我成功运行了“rake db:migrate”。

应用程序/视图/引脚/

<p>
   <strong>Manufacturer:</strong>
   <%= @pin.manufacturer %>
</p>

<% if @pin.is_multi? %>
  <p>
    <strong>Quantity:</strong>
    <%= @pin.quantity %>
 </p>
 <% end %>
 <p>
      <aside id="details-aside" class="col-sm-4">
        <!-- <a id="btn-buy" href="receipt.html" class="btn btn-success btn-lg btn-block"><b>I want this!</b></a> -->                 

      <% if @pin.user = current_user %>

          <%= form_tag charges_path, id: 'chargesForm' do %>
              <script src="https://checkout.stripe.com/checkout.js"></script>
              <%= hidden_field_tag 'stripeToken' %>
              <%= hidden_field_tag 'stripeEmail' %>  
              <button id="btn-buy" type="button" class="btn btn-success btn-lg btn-block"><span class="glyphicon glyphicon-heart"></span>   I want this!</button>

              <script>
                  var handler = StripeCheckout.configure({
                    key: '<%= Rails.configuration.stripe[:publishable_key] %>',
                    token: function(token, arg) {
                      document.getElementById("stripeToken").value = token.id;
                      document.getElementById("stripeEmail").value = token.email;
                      document.getElementById("chargesForm").submit();
                    }
                  });
                   document.getElementById('btn-buy').addEventListener('click', function(e) {
                    handler.open({
                      name: 'OMG! <%= @pin.manufacturer %>',
                      description: '<%= @pin.description %>',
                      amount: '<%= @pin.price %>'
                  });
                  e.preventDefault();
                 })
              </script>
          <% end %>

      <% else %>

          <%= link_to 'I want this!', new_user_registration_path, class: "btn btn-success btn-lg btn-block" %>

      <% end %>

app/views/pins/index.html.erb

 <%= render 'pages/home' unless user_signed_in? %>

 <h3>Listings</h3>
   <% if user_signed_in? %>
     <%= link_to '+Add Listing', new_pin_path, class: "btn btn-default" %>
     <% else %>
     <%= link_to '+Add Listing', new_user_session_path, class: "btn btn-default" %>
   <% end %>
  <%= link_to 'Buy Request', contact_path, class: "btn btn-danger" %>

  <div id="pins" class="transitions-enabled">
     <% @pins.each do |pin| %>
      <div class="box panel panel-default">
        <div class="panel-body">
          <%= link_to (image_tag pin.image.url(:medium)), pin %>
          <p></p>
          <strong>Manufacturer:</strong>
          <%= pin.manufacturer %>
          <p></p>
          <strong>Price:</strong>
          <%= pin.price %>
          <p></p>
          <strong>Description:</strong>
          <%= pin.description %>
          <% if pin.is_multi? %>
            <strong>Quantity:</strong>
              <%= pin.quantity %>
              <% end %>
             <p></p>

不确定是什么导致了问题。有关如何修补此问题的任何建议?谢谢!

【问题讨论】:

  • 我不知道你的其余代码......但这肯定是一个错误:&lt;% if @pin.user = current_user %&gt; - 你的意思是==这里吗?
  • 你也应该使用 (image_tag pin.image.url(:medium)) 而不是:image_tag(pin.image.url(:medium))
  • 至于您的实际问题...您没有向我们展示任何实际上与条带相关的代码...您如何知道条带事务已成功创建?你怎么知道价格在这个时间点应该有一个价值?你能确认你正在查看的pin 的价格是rails console 吗?
  • 在几个引脚上运行 rails console Pin.find(#) 后,它返回“price: nil”——我还能提供哪些其他信息对这里有帮助?谢谢你,很好地解决了第一个错误!
  • 是的!这完全奏效了!谢谢塔林!我没有在我的 pin 参数中包含 :price 。随意写下来,我会继续接受你的回答!

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


【解决方案1】:

好吧,经过一番折腾,最终结果是在输入价格期间出现问题,而不是输出错误......这让我想到了将价格列添加到permit./require 控制器的部分。

【讨论】:

    猜你喜欢
    • 2013-12-06
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2019-07-11
    • 2022-01-18
    • 2018-08-15
    • 2017-01-13
    相关资源
    最近更新 更多