Skip to content

Commit 060d6ca

Browse files
Indent code examples to get proper doc code output / highlight
[ci skip]
1 parent 40a5236 commit 060d6ca

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

activerecord/lib/active_record/transaction.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ module ActiveRecord
1212
# After updating the database state, you may sometimes need to perform some extra work, or reflect these
1313
# changes in a remote system like clearing or updating a cache:
1414
#
15-
# def publish_article(article)
16-
# article.update!(published: true)
17-
# NotificationService.article_published(article)
18-
# end
15+
# def publish_article(article)
16+
# article.update!(published: true)
17+
# NotificationService.article_published(article)
18+
# end
1919
#
2020
# The above code works but has one important flaw, which is that it no longer works properly if called inside
2121
# a transaction, as it will interact with the remote system before the changes are persisted:
2222
#
23-
# Article.transaction do
24-
# article = create_article(article)
25-
# publish_article(article)
26-
# end
23+
# Article.transaction do
24+
# article = create_article(article)
25+
# publish_article(article)
26+
# end
2727
#
2828
# The callbacks offered by ActiveRecord::Transaction allow to rewriting this method in a way that is compatible
2929
# with transactions:
3030
#
31-
# def publish_article(article)
32-
# article.update!(published: true)
33-
# Article.current_transaction.after_commit do
34-
# NotificationService.article_published(article)
31+
# def publish_article(article)
32+
# article.update!(published: true)
33+
# Article.current_transaction.after_commit do
34+
# NotificationService.article_published(article)
35+
# end
3536
# end
36-
# end
3737
#
3838
# In the above example, if +publish_article+ is called inside a transaction, the callback will be invoked
3939
# after the transaction is successfully committed, and if called outside a transaction, the callback will be invoked

0 commit comments

Comments
 (0)