-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Improvements to ActiveRecord::Rollback docs #42874
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
Conversation
Hey @jjb, thanks for the PR! I can see how the "Call tech support" line is confusing. What do you think about adding the |
done - if that looks good i can squish the two commits
by this do you mean it's difficult to understand, or it's not emblematic of intended use case, or something else? I think the docs currently in main are not emblematic of a typical use case, if you agree i wonder if we can improve the docs without making them too complex. |
@jjb adding the Author and Stats models makes things more complex. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! 🚢
Please squash the commits.
the "Call tech support" message in the example is confusing in this scenario, because it's addressing the user, but the user will never see it. Also added a note emphasizing what behavior will be in the normal error case
@p8 squashed |
Co-authored-by: Petrik de Heus <petrik@deheus.net>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
@p8 okay, done would you consider replacing the |
I’m okay with that. I like some light hearted reading, but it shouldn’t be at the cost of understandability. Maybe we should show the example in a model instead of a controller. An Order that requires the Book to be in the inventory? This allows us to skip all the rendering logic and use a more realistic example? |
in that scenario, which operations should raise and which operations should continue on? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Hi @p8 - if you have time and interest to answer my question I can maybe put something together, thanks! |
Hi @jjb sorry for the late reply 😞 Maybe we can render a different flash depending on whether the book was saved? # class BooksController < ActionController::Base
# def create
# book = Book.new(params[:book])
# Book.transaction do
# book.save!
# # If this fails, we rollback this transaction and pass on the exception.
# # The user gets generic 500 behavior.
# Stats.create!(type: 'book_purchase')
# 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
# end
# end
# # ActiveRecord::Rollback is the only exception that won't be passed on
# # by ActiveRecord::Base.transaction, so this will still be reached
# # even on Friday.
# if book.persisted?
# redirect_to root_url, notice: "Book purchased"
# else
# redirect_to root_url, alert: "Call tech support!"
# end
# end |
thanks for looping back - i won't be able to work on this unfortunately - maybe someone else can pick it up and work with what i've suggested |
The main problem I wanted to solve is that the "Call tech support" message in the example is
confusing in this scenario, because it's addressing the user, but the user will never see it.
I'm not sure if I'm not understanding something, or maybe this was copy/pasted from
another example years ago.
Here I remove that and also expand the docs, hopefully illustrating the concept better.
Any and all feedback on copy, phrasing, formatting, examples, is welcome!