Forum: Ruby on Rails transactions rollback question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1b9cfd9892a765221fe557768987b42d?d=identicon&s=25 Juan Matias (jmrepetti)
on 2007-07-04 01:23
I have something like this:

def import_from_csv(csv_file)

  Item.transaction do
    FasterCSV.foreach(csv_file.path) do |row|
      item = Item.new(:name => row[0], :units => row[1], :price =>
row[2])
      item.save!
    end
  end #transaction

end

If I got a negative price I want to rollback all items saved.It's
possible?
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-07-04 01:37
(Received via mailing list)
On Jul 4, 2007, at 1:23 AM, Juan Matias wrote:

> If I got a negative price I want to rollback all items saved.It's
> possible?

Sure, just raise an exception.

-- fxn
This topic is locked and can not be replied to.