I can’t redirect correctly, it keeps throwing me ActiveRecord::RecordInvalid but it should be redirecting :back to the original page.
def create_multiple
Product.transaction do
begin
@products = current_user.products.create!(params[:products].map { |_k, p| p.merge params[:product] })
redirect_to :back, :notice => "Success!"
rescue ActiveRecord::Rollback
redirect_to :back, :notice => "An error occured, please try again."
end
end
end
end
How do I get it to redirect?
If you want to catch the ActiveRecord::RecordInvalid exception, then why aren’t you rescuing that instead of ActiveRecord::Rollback?
I would write this function something like the above.