Skip to content

Improvements to ActiveRecord::Rollback docs #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions activerecord/lib/active_record/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,17 @@ class StrictLoadingViolationError < ActiveRecordError
# class BooksController < ActionController::Base
# def create
# Book.transaction do
# book = Book.new(params[:book])
# book.save!
# if today_is_friday?
# # The system must fail on Friday so that our support department
# # won't be out of job. We silently rollback this transaction
# # without telling the user.
# raise ActiveRecord::Rollback, "Call tech support!"
# Stats.create!(type: 'book_purchase', params[:userinfo]) # If this fails, user gets generic 500 behavior
# author = Author.find_or_create_by!(params[:author]) # If this fails, user gets generic 500 behavior
# @book = author.books.build(params[:book])
# if @book.save # note that we are using save, not save!
# redirect_to @book and return # success behavior
# else
# # If @book.save fails, we roll back Stats and Author db modifications and inform the user about the problem with @book
# raise ActiveRecord::Rollback
# end
# end
# # ActiveRecord::Rollback is the only exception that won't be passed on
# # by ActiveRecord::Base.transaction, so this line will still be reached
# # even on Friday.
# redirect_to root_url
# render 'new' # this line is only reached if @book.save fails
# end
# end
class Rollback < ActiveRecordError
Expand Down