我正在设置表单,以便用户可以添加新的Stripe信用卡。我在表单上收到First argument in form cannot contain nil or be empty
<{1}}
我到底错过了什么,以便我可以将表格提交给Stripe?
订阅控制器:
<%= form_for @subscription do |f| %>
形式:
def new
plan = Plan.find(params[:plan_id])
@subscription = plan.subscriptions.build
if params[:PayerID]
@subscription.paypal_customer_token = params[:PayerID]
@subscription.paypal_payment_token = params[:token]
@subscription.email = @subscription.paypal.checkout_details.email
end
end
def create
@subscription = Subscription.new(params[:subscription])
if @subscription.save_with_payment
redirect_to @subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
def show
@subscription = Subscription.find(params[:id])
end
def paypal_checkout
plan = Plan.find(params[:plan_id])
subscription = plan.subscriptions.build
redirect_to subscription.paypal.checkout_url(
return_url: new_subscription_url(:plan_id => plan.id),
cancel_url: root_url
)
end
def updatesubscription
@user = current_user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
@customer.update_subscription(:plan => "1", :prorate => true)
current_user.save!
flash.alert = 'Your subscription has been updated!'
redirect_to root_url
end
def cancelsubscription
@user = current_user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
@customer.cancel_subscription()
current_user.save!
flash.alert = 'Your subscription has been cancelled successfully!'
redirect_to root_url
end
def create_card_stripe
@user = current_user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)
@customer.cards.create({
:card => @user.subscription.stripe_customer_token
})
@user.update_attribute(:stripe_card_id, customer.active_card.id)
if customer.save
flash.alert = "Credit card updated successfully!"
redirect_to root_url
else
flash.alert = "Error with updating card"
redirect_to root_url
end
end
end
答案 0 :(得分:1)
您收到错误,因为@subscription
为零。
在订阅控制器@subscription
中设置action
的值,以呈现此视图。