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

Docs: Replace "off" with false [ci skip] #49936

Merged
merged 1 commit into from Nov 6, 2023

Conversation

seanpdoyle
Copy link
Contributor

Detail

Replace a reference to a default "off" value in the ActiveRecord::NestedAttributes module with the actual default value: false.

@@ -307,7 +307,7 @@ module ClassMethods
# [:allow_destroy]
# If true, destroys any members from the attributes hash with a
# <tt>_destroy</tt> key and a value that evaluates to +true+
# (e.g. 1, '1', true, or 'true'). This option is off by default.
# (e.g. 1, '1', true, or 'true'). This option is +false+ by default.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: I think "false" here should not use monospace because it is not referring to the false singleton. In this case, the default is actually (probably) nil, but that does not matter to the user, so we can say "false" to contrast with "If true".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, the default is actually (probably) nil

@jonathanhefner I might be misreading the implementation, but the default options declare allow_destroy: false:

def accepts_nested_attributes_for(*attr_names)
options = { allow_destroy: false, update_only: false }
options.update(attr_names.extract_options!)
options.assert_valid_keys(:allow_destroy, :reject_if, :limit, :update_only)
options[:reject_if] = REJECT_ALL_BLANK_PROC if options[:reject_if] == :all_blank

I'm happy to remove the wrapping + characters, but I want to make sure that I understand the implications first.

Copy link
Member

@p8 p8 Nov 6, 2023

Choose a reason for hiding this comment

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

+false+ is inline with the description of :update_only: By default the +:update_only+ option is +false+.
Maybe also change If true, destroys to If +true+, destroys ? ...although I don't have a strong opinion here.

Copy link
Member

@p8 p8 Nov 6, 2023

Choose a reason for hiding this comment

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

Reading the link from @jonathanhefner I agree with his suggestion.

Do not document singletons unless absolutely necessary (as) that... allows refactors, and the code does not need to rely on the exact values returned by methods being called in the implementation.

Copy link
Member

Choose a reason for hiding this comment

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

You are correct about it being false; I didn't actually look at the implementation and just assumed it was nil. But the point is that it doesn't matter to the user — indeed, the user will never see or interact with this value — and we could change the implementation to use nil without the user knowing.

In other words, the default is "falsy", just like the enabling value merely needs to be "truthy", not true. But we avoid those words in Rails documentation in favor of "false" and "true" without monospace formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonathanhefner thank you for sharing the link to https://guides.rubyonrails.org/v7.1/api_documentation_guidelines.html#booleans, I had no idea there were style guides for documentation! I'll read up on the rest of what's provided there.

In the meantime, with the Boolean documentation in mind, is this diff valuable at all? Is "false" an improvement over "off"? Should I replace +false+ with false, or would it be better to close this without change?

Copy link
Member

Choose a reason for hiding this comment

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

We should not use +false+. I don't have a strong opinion on "false" vs "off", but if you think it reads more clearly, then I'm 👍.

Copy link
Member

@p8 p8 Nov 6, 2023

Choose a reason for hiding this comment

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

@seanpdoyle seanpdoyle force-pushed the ar-nested-attributes-default branch 2 times, most recently from 3e839e4 to 3e42dc6 Compare November 6, 2023 16:51
Replace a reference to a default `"off"` value in the
`ActiveRecord::NestedAttributes` module with the actual default value:
`false`.
@seanpdoyle seanpdoyle requested a review from p8 November 6, 2023 17:23
@jonathanhefner jonathanhefner merged commit 488a7ce into rails:main Nov 6, 2023
@jonathanhefner
Copy link
Member

Thank you, @seanpdoyle! 0️⃣ 1️⃣ 0️⃣ And thank you, @p8! 👋

@seanpdoyle seanpdoyle deleted the ar-nested-attributes-default branch November 6, 2023 17:27
jonathanhefner added a commit that referenced this pull request Nov 6, 2023
Docs: Replace "off" with `false` [ci skip]

Co-authored-by: Petrik <petrik@deheus.net>
(cherry picked from commit 488a7ce)
jonathanhefner added a commit that referenced this pull request Nov 6, 2023
Docs: Replace "off" with `false` [ci skip]

Co-authored-by: Petrik <petrik@deheus.net>
(cherry picked from commit 488a7ce)
@zzak
Copy link
Member

zzak commented Nov 24, 2023

I'm not sure this applies here, but reminded me of the guide for booleans.

@p8
Copy link
Member

p8 commented Nov 25, 2023

@zzak Jonathan mentioned that as well above: #49936 (comment)

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.

None yet

4 participants