Rails 5.2.4.4
ruby 2.5.1p57
で開発しています。
したいこと:
stripeを使ってカード決済
エラー
#NoMethodError (undefined method `map' for "1":String Did you mean? tap):
show.html.erb
**show.html.erb** <div class="container"> <h3 class="text-center mb-30"> Stuff in your basket </h3> <% if @items.any? %> <% @items.each do |item| %> <ul class="row-col-1 border border-dark d-flex justify-content-between px-5 py-2 mb-3"> <li class="collection-item"> <%= item.name %> </li> <li class="collection-item "> <%= item.price%> <%= link_to "delete", item_delete_in_baskets_path(item), method: :post, data: { confirm: "You sure?" }, class:"ml-2"%> </li> </ul> <% end %> <div class="basket_total_amount float-right"> <%= "Total price:: CDN $ #{@total_price}" %> </div> <%= form_tag charge_path do %> <% @items.each do |p|%> **<%= hidden_field_tag :item_ids, p.id %>ト** <% end %> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="<%= ENV['STRIPE_API_KEY']%>" date-description="payment" data-amount="<%= @total_price %>" data-locale="auto" data-currency="cdn"> </script> <% end %> <% else %> <h3 class="text-center" id="basket_nop">...you have nothing on your basket</h3> <% end %> </div>
charges_controller
**charges_controller** class ChargesController < ApplicationController def create Stripe.api_key = ENV['STRIPE_SECRET_KEY'] token = params[:stripeToken] item_ids = params[:item_ids].map(&:to_i) items = current_user.basket.items.where(id: item_ids) total = items.sum[:price] Stripe::Charge.create({ amount: total, currency: 'cdn', description: 'Example charge', source: token }) redirect_to root_path, success: 'success your payment' end end
terminal
Parameters: {"utf8"=>"✓","item_ids"=>"1"} NoMethodError (undefined method `map' for "1":String Did you mean? tap):
どなたかアドバイス頂けたら嬉しいです。
回答1件
あなたの回答
tips
プレビュー