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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci-skip] Adding options example in ActiveModel::Errors doc #41217

Merged
merged 1 commit into from
Feb 3, 2021

Conversation

Vin0uz
Copy link
Contributor

@Vin0uz Vin0uz commented Jan 23, 2021

馃憢

This diff closes #41124

As stated in the issue, a quick example of how options can be used to be part of the generated message was missing, but appearing in another method doc (added?)

I didn't move the piece in added? because it seems to be well-belonging there, but copied the example in add

@@ -381,6 +381,11 @@ def group_by_attribute
# If +type+ is a proc, it will be called, allowing for things like
# <tt>Time.now</tt> to be used within an error.
#
# If +type+ is compatible, +options+ will be injected in the translation.
Copy link
Member

Choose a reason for hiding this comment

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

Instead of placing this here, I would put it directly under the If +type+ is a symbol... line and add an example with and without interpolation like:

person.errors.add(:name, :blank)
person.errors.messages
# => {:name=>["can't be blank"]}

person.errors.add(:name, :too_long, { count: 25 })
person.errors.messages
# => ["is too long (maximum is 25 characters)"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's indeed a nicer way to do it, thank !

@rafaelfranca
Copy link
Member

Could you please squash your commits in one?

# person.errors.add(:name, :blank)
# person.errors.messages
# # => {:name=>["can't be blank"]}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#

Copy link
Contributor Author

Choose a reason for hiding this comment

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

馃檲 thanks

Place errors with variable example under the `type is a symbol` block
Closes rails#41124
@Vin0uz Vin0uz force-pushed the active-model-errors-add-doc branch from aef697f to da0e869 Compare February 3, 2021 20:56
@rafaelfranca rafaelfranca merged commit da418dc into rails:main Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActiveModel::Errors#add docs example misplaced
4 participants