public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Improve documentation of ActiveRecord::Rollback.
Hongli Lai (Phusion) (author)
Sat Jul 19 03:19:20 -0700 2008
commit  2fd540a266ad92230b4e565474b627f825993732
tree    f3d57bb3b7349a71ad74f56efd4255a0f21231cd
parent  038c7fdeea33d7aabc918b29304a262b663e3604
...
83
84
85
86
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
89
90
...
83
84
85
 
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
0
@@ -83,8 +83,33 @@ module ActiveRecord #:nodoc:
0
   class ReadOnlyRecord < ActiveRecordError
0
   end
0
 
0
- # Used by Active Record transaction mechanism to distinguish rollback from other exceptional situations.
0
- # You can use it to roll your transaction back explicitly in the block passed to +transaction+ method.
0
+ # ActiveRecord::Transactions::ClassMethods.transaction uses this exception
0
+ # to distinguish a deliberate rollback from other exceptional situations.
0
+ # Normally, raising an exception will cause the +transaction+ method to rollback
0
+ # the database transaction *and* pass on the exception. But if you raise an
0
+ # ActiveRecord::Rollback exception, then the database transaction will be rolled back,
0
+ # without passing on the exception.
0
+ #
0
+ # For example, you could do this in your controller to rollback a transaction:
0
+ #
0
+ # class BooksController < ActionController::Base
0
+ # def create
0
+ # Book.transaction do
0
+ # book = Book.new(params[:book])
0
+ # book.save!
0
+ # if today_is_friday?
0
+ # # The system must fail on Friday so that our support department
0
+ # # won't be out of job. We silently rollback this transaction
0
+ # # without telling the user.
0
+ # raise ActiveRecord::Rollback, "Call tech support!"
0
+ # end
0
+ # end
0
+ # # ActiveRecord::Rollback is the only exception that won't be passed on
0
+ # # by ActiveRecord::Base.transaction, so this line will still be reached
0
+ # # even on Friday.
0
+ # redirect_to root_url
0
+ # end
0
+ # end
0
   class Rollback < ActiveRecordError
0
   end
0
 

Comments

    No one has commented yet.