我有一个order_items
的购物车。 OrderItem
有一个product_id
和多个book_ids
。当我有多个order_items
即两个产品时,Order.create
只接受第一个product_id
。
结帐表单
<%= form_tag charges_path do %>
<h4><% current_order.subtotal %></h4>
<div class="form-group">
</div>
<script
class='stripe-button'
src="https://checkout.stripe.com/checkout.js"
data-key="<%= @stripe_btn_data %>"
data-amount=<%= current_order.subtotal %>
data-description="<%= @order_items.count %>"
data-shipping-address="true"
data-billing-address="<%= @stripe_btn_data %>"
></script>
<% @order_items.each do |oi| %>
<%= hidden_field_tag :product_id, oi.id %>
<% end %>
<% end %>
在ChargeController内部的Order.create
def create
@product = Product.find(params[:product_id])
Order.create(
user: current_user,
stripe_billing_name: params[:stripeBillingName],
stripe_shipping_name: params[:stripeShippingName],
stripe_authenticity_token: params[:authenticity_token],
stripe_email: params[:stripeEmail],
stripe_billing_address_country_code: params[:stripeBillingAdressCountryCode],
stripe_shipping_address_country_code: params[:stripeShippingAdressCountryCode],
stripe_shipping_address_country: params[:stripeShippingAdressCountry],
stripe_billing_address_country: params[:stripeBillingAdressCountry],
billing_address: params[:stripeBillingAddressLine1],
billing_city: params[:stripeBillingAddressCity],
billing_state: params[:stripeBillingAddressState],
billing_zip: params[:stripeBillingAddressZip],
shipping_address: params[:stripeShippingAddressLine1],
shipping_city: params[:stripeShippingAddressCity],
shipping_state: params[:stripeShippingAddressState],
shipping_zip: params[:stripeShippingAddressZip],
product_id: params[:product_id]
end
product_id
为1和2时,我得到product_id
2的最终结果
如何在product_ids
上获取所有Order.create
?
答案 0 :(得分:1)
我认为你可以尝试这样的事情
<% @order_items.each do |oi| %>
<%= hidden_field_tag 'product_ids[]', oi.id %>
<% end %>
答案 1 :(得分:0)
怎么样?
<% @order_items.each do |oi| %>
<%= hidden_field_tag 'product_ids[]'.to_i, oi.id %>
<% end %>