Reputation: 4629
I have a model that, when a record is inserted, needs to call a webservice.
If the webservice fails ( timeout or other failures ), them the save in database should also be reverted.
I used the after_save callback and tried to raise an ActiveRecord::Rollback when this kind of error happens.
Although it returns false on object.save, it doesn't rollback the transaction. What is the proper way of doing this?
How can i also make sure that the record won't be created?
Upvotes: 1
Views: 969
Reputation: 3919
Are you wrapping this in an Active Record Transaction block?
User.transaction do
User.create(:username => 'Kotori')
User.transaction(:requires_new => true) do
User.create(:username => 'Nemu')
raise ActiveRecord::Rollback
end
end
Also See:
http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html
Upvotes: 1