Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min_size and max_size to :file_size_out_of_range error message #134

Conversation

kemenaran
Copy link
Contributor

@kemenaran kemenaran commented Sep 28, 2021

Currently, the error message for an invalid file size can't include the expected min or max size of the file.

The error message only states:

"Attachment size %{file_size} is not between required range"


This PR allows using the interpolated variables %{min_size} and %{max_size} in the localized error message string.

Thus the error message can be customized by projects using this gem to look like this:

"Attachment size %{file_size} is larger than the required size %{max_size}"

Future work

For now, the error message doesn't include the size information by default. The extra information must be added by projects using the gem.

In a future PR, I'd like to introduce new localized strings for "too large" and "too small" errors, which would allow to have the default error messages mention the string by default. (This is more work because of retro-compatibility concerns though).

This allow to use the interpolated variables `%{min_size}` and
`%{max_size}` in the localized error message string.
@kemenaran
Copy link
Contributor Author

@igorkasyanchuk would that be interesting for the project, and is there something I could do to move this PR forward?

@igorkasyanchuk igorkasyanchuk merged commit 1b84896 into igorkasyanchuk:master Nov 23, 2021
@igorkasyanchuk
Copy link
Owner

merged, sorry, missed it, today will release a newer version

@igorkasyanchuk
Copy link
Owner

0.9.6 released

@kemenaran
Copy link
Contributor Author

Hey, that's great, thanks a lot!

@kemenaran kemenaran deleted the min-max-size-in-validation-message branch November 23, 2021 21:50
kemenaran added a commit to demarches-simplifiees/demarches-simplifiees.fr that referenced this pull request Nov 24, 2021
This allows us to have the %{file_max_size} variable defined in the
error message.

See igorkasyanchuk/active_storage_validations#134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants