我试图在def create方法中传递以下内容。 create方法位于事务控制器中。
@purchases = current_shop.purchases.build(purchase_params)
@purchases.save!
private
def purchase_params
params.require(:purchase).permit(:shop_id, :subscription_id, :created_at)
end
并返回此错误:
ActionController::ParameterMissing in TransactionsController#create
param is missing or the value is empty: purchase
更新1
日志:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"aJWUUEwgtG0o52MEHSOcNETj1Ueo+4NvLBD+y5LMPHxtHnOEe1Zgs3IMADdv5y+dbl7Ecgr8LMEjIG6sws9kqg==", "payment_method_nonce"=>"bf7458d2-d3a4-02c9-2593-526174f50822"}
Cart Load (0.1ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT ? [["id", 93], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = ? ORDER BY "shops"."id" ASC LIMIT ? [["id", 13], ["LIMIT", 1]]
LineItem Load (0.4ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = ? [["cart_id", 93]]
Subscription Load (0.1ms) SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Completed 400 Bad Request in 2899ms (ActiveRecord: 1.1ms)
ActionController::ParameterMissing (param is missing or the value is empty: purchase):
app/controllers/transactions_controller.rb:60:in purchase_params'
app/controllers/transactions_controller.rb:31:in create'
更新2
<p id="notice"><%= notice %></p>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<div class="form-container radius-box glassy-bg small-10 small-centered medium-8 large-6 columns">
<h2 class="mbs">New Transaction</h2>
<%= form_tag transactions_path do%>
<p>Please enter your payment details:</p>
<div id="dropin"></div>
<%=submit_tag "Pay #{@cart.total_price}$", class: "button mt1" %>
<%end%>
</div>