我需要在我的Rails應用程序中做一些奇怪的事情。一旦用戶通過創建操作創建產品實例,我需要它保存,然後將它們重定向到Braintree付款方式表單,如果他們還沒有在其帳戶中添加一個表單,並將其重定向到展示頁面產品。Rails控制器重定向到另一個控制器,然後返回到保存的模型
這裏的產品創建行動:
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
的布倫特裏客戶控制器確認方法是這樣的:
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
就是我想要做的可能嗎?
你可以試試'redirect_to @ result.customer.products.last' – 2014-09-04 07:35:54