所以这是我试图嵌套一个 div 元素(一个贝宝按钮)和一个按钮元素(提交表单的 rails 元素)的情况也重定向到贝宝付款页面。### 请告诉我任何其他方式。如果我走错了路###。这是代码
<%= form_for([@listing, @order]) do |form| %>
<% if order.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(order.errors.count, "error") %> prohibited this order from being saved:</h2>
<ul>
<% order.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= form.label :name %>
<%= form.text_field :name, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :size %>
<%= form.text_field :size, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :mobile %>
<%= form.text_field :mobile, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :city %>
<%= form.text_field :city, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :address %>
<%= form.text_field :address, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :PinCode %>
<%= form.text_field :PinCode, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :Landmark %>
<%= form.text_field :Landmark, class:"form-control" %>
</div>
<div class="form-group">
<%= form.label :Description %>(if any special changes)
<%= form.text_field :Description, class:"form-control" %>
</div>
<div class="form-group">
<%=form.submit%>
<%=link_to "Checkout" %>
</div>
<button type="submit" onClick="placeOrder(this.form)" class="button button2">
<!-- Set up a container element for the button -->
<div id="paypal-button-container"> </div>
<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=sb¤cy=USD"></script>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}
}).render('#paypal-button-container');
</script>
<%=form.submit%>
Place Order</button>