faint-manchester-51052
05/27/2024, 6:13 PMminiature-optician-85831
05/27/2024, 6:13 PMlemon-wall-20836
05/27/2024, 6:23 PMlemon-wall-20836
05/27/2024, 6:23 PMlemon-wall-20836
05/27/2024, 6:24 PMruby
def perform_action_and_record_errors(&block)
begin
succeeded = block.call
rescue => exception
# In case there's an error somewhere else than the model
# Example: When you save a license that should create a user for it and creating that user throws and error.
# Example: When you Try to delete a record and has a foreign key constraint.
exception_message = exception.message
end
# Add the errors from the model
@errors = @model.errors.full_messages.reject { |error| exception_message.include? error }.unshift exception_message
succeeded
endlemon-wall-20836
05/27/2024, 6:25 PMexception_message somehowlemon-wall-20836
05/27/2024, 6:25 PMlemon-wall-20836
05/27/2024, 6:25 PMfaint-manchester-51052
05/27/2024, 6:26 PMlemon-wall-20836
05/27/2024, 6:26 PMlemon-wall-20836
05/27/2024, 6:27 PMmainlemon-wall-20836
05/27/2024, 6:39 PMlemon-wall-20836
05/27/2024, 6:40 PMlemon-wall-20836
05/27/2024, 6:42 PMfaint-manchester-51052
05/27/2024, 6:42 PMlemon-wall-20836
05/27/2024, 6:43 PM