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