Created
May 26, 2011 14:55
-
-
Save arbarlow/993308 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the wrong was to do this. What if one of the order products fails? | |
def create | |
@order = Order.new | |
if @order.save | |
for order in params[:order][:product_ids] | |
OrderProducts.create(:order_id => @order.id, :product_id => Product.find(params[:id]).id) | |
end | |
flash[:notice] = "Thanks, your order will be completed shortly!" | |
redirect_to :action => "index" | |
else | |
render :action => "new" | |
end | |
end | |
# On save, this will save and validate all the order_products too | |
def create | |
@order = Order.new | |
for order in params[:order][:product_ids] | |
@order.order_products.build(:product => Product.find(params[:id])) | |
end | |
if @order.save | |
flash[:notice] = "Thanks, your order will be completed shortly!" | |
redirect_to :action => "index" | |
else | |
render :action => "new" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment