我需要在我的 Rails 应用程序中做一些奇怪的事情。一旦用户通过 create 操作创建了 Product 实例,如果他们尚未将其添加到他们的帐户中,我需要将其保存并重定向到 Braintree 付款方式表单,然后才将他们重定向到显示页面产品。
这是产品创建操作:
def create
@product = Product.new(product_params)
@product.set_user!(current_user)
if @product.save
if !current_user.braintree_customer_id?
redirect_to "/customer/new"
else
redirect_to view_item_path(@product.id)
end
else
flash.now[:alert] = "Woops, looks like something went wrong."
format.html {render :action => "new"}
end
end
Braintree 客户控制器的确认方法是这样的:
def confirm
@result = Braintree::TransparentRedirect.confirm(request.query_string)
if @result.success?
current_user.braintree_customer_id = @result.customer.id
current_user.customer_added = true
current_user.first_name = @result.customer.first_name
current_user.last_name = @result.customer.last_name
current_user.save!
redirect_to ## not sure what to put here
elsif current_user.has_payment_info?
current_user.with_braintree_data!
_set_customer_edit_tr_data
render :action => "edit"
else
_set_customer_new_tr_data
render :action => "new"
end
end
我想做的事可能吗?