Skip to content

Instantly share code, notes, and snippets.

@vaz
Created November 15, 2016 19:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaz/8984603dd5c868d2e0dc7f087c0c51c5 to your computer and use it in GitHub Desktop.
Save vaz/8984603dd5c868d2e0dc7f087c0c51c5 to your computer and use it in GitHub Desktop.
AR or Statesman, error handling patterns in controller (sort of pseudocode)
# 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