Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.