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 Formatting Full Messages with I18n section in ActiveRecordValidations guides [ci-skip] #45470

Merged
merged 1 commit into from Jul 7, 2022

Conversation

AlexB52
Copy link
Contributor

@AlexB52 AlexB52 commented Jun 27, 2022

Summary

This PR adds a section on the ActiveRecordValidation guides to demonstrate how full validation messages can be formatted with the help of I18n.

Other Information

This PR was extracted from the PR proposal: #42708
While the feature didn't get any traction, the documentation of the existing behaviour to format full messages is currently missing.

@rails-bot rails-bot bot added the docs label Jun 27, 2022
@AlexB52 AlexB52 changed the title Add Formatting Full Messages with I18n section in ActiveRecordValdidations guides [ci-skip] Add Formatting Full Messages with I18n section in ActiveRecordValidations guides [ci-skip] Jun 27, 2022
Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about putting this information under config.active_model.i18n_customize_full_message instead? We could perhaps streamline the examples to use a single model with ActiveModel::Validations and a single validation on two different attributes. Then we could add a comment like # or `activerecord:` if using Active Record validations next to the activemodel: key in the YAML.

@AlexB52
Copy link
Contributor Author

AlexB52 commented Jun 29, 2022

@jonathanhefner the suggested change sounds good.

I really feel that it's relevant for validations and i18n too and left in the configuration page is really hiding the information. Can we also add a link on these guides to the configuration example?

I'm thinking here: 7.3 errors.where and error object

under

The full_message method generates a more user-friendly message, with the capitalized attribute name prepended.

and here: active-model-methods

on this paragraph

ActiveModel::Errors#full_messages prepends the attribute name to the error message using a separator that will be looked up from errors.format (and which defaults to "%{attribute} %{message}").

I'll put some links in the meantime.
Cheers

@jonathanhefner
Copy link
Member

I really feel that it's relevant for validations and i18n too. Can we also add a link on these guides to the configuration example?

@AlexB52 Sounds good! 👍

@AlexB52 AlexB52 force-pushed the doc-full-message-format branch 2 times, most recently from 0706a1c to 2fea677 Compare June 30, 2022 01:37
guides/source/configuring.md Outdated Show resolved Hide resolved
guides/source/configuring.md Outdated Show resolved Hide resolved
guides/source/configuring.md Outdated Show resolved Hide resolved
guides/source/configuring.md Outdated Show resolved Hide resolved
guides/source/i18n.md Outdated Show resolved Hide resolved
guides/source/active_record_validations.md Outdated Show resolved Hide resolved
Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor comments. Almost there! 😃

Also, when you're finished, would you mind squashing the commits?


When set to `true`, `full_message` will look for a format at the attribute and model level of the locale files. The default format is `"%{attribute} %{message}"`, where `attribute` is the name of the attribute, and `message` is the validation-specific message. The following example overrides the format for all `Person` attributes, as well as the format for a specific `Person` attribute (`age`).

[ActiveModel::Error#full_message]: https://api.rubyonrails.org/classes/ActiveModel/Error.html#method-i-full_message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this reference below the example, at the end of this section, above the ### Configuring Active Record heading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I just moved the link below the code example. I hope this is what you meant and not the paragraph starting with
when set to 'true'...

guides/source/configuring.md Show resolved Hide resolved
guides/source/active_record_validations.md Outdated Show resolved Hide resolved
guides/source/i18n.md Outdated Show resolved Hide resolved
@AlexB52 AlexB52 force-pushed the doc-full-message-format branch 2 times, most recently from e835480 to fb49e1e Compare July 6, 2022 20:08
@AlexB52
Copy link
Contributor Author

AlexB52 commented Jul 6, 2022

@jonathanhefner
I removed the intermediary commit messages during the squash as I thought that wasn't really helpful and would be more noise. I left the co-authoring statement.

Can you please check if the commit message suits you?

I have a backup of all the commits in case a standard squash with the 12 commits in the description is necessary.

Thanks for the help
Cheers

…eRecord

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
@jonathanhefner jonathanhefner merged commit e722b74 into rails:main Jul 7, 2022
@jonathanhefner
Copy link
Member

jonathanhefner commented Jul 7, 2022

There was a commit that accidentally removed a line break. (I probably should have included the line break in #45470 (comment).) I forced pushed a commit to fix it though, so we're good to go. Thank you for working on this, @AlexB52! 👍

(Backported to 7-0-stable.)

@AlexB52 AlexB52 deleted the doc-full-message-format branch July 7, 2022 21:06
jonathanhefner added a commit that referenced this pull request Jul 24, 2022
Add Formatting Full Messages with I18n section in ActiveRecordValidations guides [ci-skip]

(cherry picked from commit e722b74)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants