newb here。我正在嘗試在創建和保存訂單和關係時執行交易。幾乎就像你必須付錢才能跟隨某人。訂單保存後,關係被創建並保存。Rails交易
def create
@order = current_cart.build_order(params[:order])
@order.ip_address = request.remote_ip
if @order.save
if @order.purchase
respond_to do |format|
Order.transaction do
begin
@order.cart.line_items.all.each do |item|
current_user.person_relationships.build(:owned_id => item.person_id)
end
end
format.html {redirect_to root_path, :flash => {:success => "Transaction Success" } }
format.xml{render xml: root_path}
rescue ActiveRecord::RecordInvalid
format.html {render :action => "failure" }
format.xml {render :action => "failure"}
raise ActiveRecord::Rollback
end
end
end
end
訂單創建時出現問題。就好像該方法跳過項目塊並創建了訂單,但沒有創建人員關係。回答可能的鏈接也非常感謝。
在此先感謝。
這將是有益的,看看模特太 – ScottJShea 2012-02-27 05:51:08