Created
November 15, 2016 19:59
-
-
Save vaz/8984603dd5c868d2e0dc7f087c0c51c5 to your computer and use it in GitHub Desktop.
AR or Statesman, error handling patterns in controller (sort of pseudocode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ActiveRecordish pattern | |
def create | |
@thing = Thing.create!(thing_params) | |
redirect_to @thing | |
rescue Thing::Invalid #??? | |
# flash error | |
# re-render | |
end | |
def create | |
# if (@thing = Thing.create(thing_params)) | |
# redirect_to @thing | |
# else | |
# flash[:error] = 'bad thing' | |
# # render show page again | |
# end | |
end | |
# similar for statesman I think? | |
def cancel | |
# unless @evaluation.transition_to(:cancelled) | |
# add flash error | |
# end | |
begin | |
@evaluation.transition_to!(:cancelled) | |
rescue Statesman::TransitionFailed, Statesman::GuardFailedError | |
# add flash error | |
end | |
redirect_to @project | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment