Handle Rails validation errors in TurboStreamable concern

This commit is contained in:
Andreas Nedbal 2023-10-15 06:39:50 +02:00 committed by Andreas Nedbal
parent ec05b3c062
commit d40519dffa
1 changed files with 2 additions and 0 deletions

View File

@ -23,6 +23,8 @@ module TurboStreamable
render_error t("errors.parameter_error", parameter: e.instance_of?(KeyError) ? e.key : e.param.capitalize)
rescue Dry::Types::CoercionError, Dry::Types::ConstraintError
render_error t("errors.invalid_parameter")
rescue ActiveRecord::RecordInvalid => e
render_error e.record.errors.full_messages.flatten.join(" ")
rescue ActiveRecord::RecordNotFound
render_error t("errors.record_not_found")
end