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
Mention associations in Form Helpers guide [ci-skip] #45779
Mention associations in Form Helpers guide [ci-skip] #45779
Conversation
guides/source/form_helpers.md
Outdated
@@ -581,25 +581,40 @@ Outputs a select box like: | |||
|
|||
For each of these helpers, you may specify a date or time object instead of a number as the default value, and the appropriate temporal component will be extracted and used. | |||
|
|||
Choices from a Collection of Arbitrary Objects | |||
---------------------------------------------- | |||
Choices from a Collection of Complex Objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Complex Objects" is a bit confusing to me, as I don't know what defines a complex object.
I think in all these cases the collections contain model objects, so maybe:
Choices from a Collection of Complex Objects | |
Choices from a Collection of Model Objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open to rewording, but I was trying to avoid "model" (right here) because I didn't want the reader to assume that these helpers only work with Active Record or Active Model objects. (I realize the term "model" is more generic than that, but, in the context of Rails, there is a strong connotation of being one of those two.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but I think in most cases it would be a collection of Active Record or Active Model objects anyway. Anyone that sees non Active Record/Model objects as models too will probably understand these objects can be used in the helpers as well.
The example uses an Active Record model as well.
I was trying to think of a non Active Record/Model object that could also be used instead (country?, locale?) but that wouldn't make the example any clearer I think.
Another option could be "Domain Objects" or removing it altogether:
Choices from a Collection of Complex Objects | |
Choices from a Collection of Objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An array of strings is a "Collection of Objects" too. 😜
How does "Compound Objects" or "Composite Objects" sound to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you can pass arrays 😄 :
<%= form.collection_select :city_id, [[3, "Berlin"], [1, "Chicago"], [2, "Madrid"]], :first, :last %>
I'm not seeing how the following should be seen as a collection of "Compound Objects" or "Composite Objects":
<% Country = Struct.new(:country_code, :name) %>
<%= form.collection_select :country_code, [Country.new(:us, "United States"), Country.new(:jp, "Japan")], :country_code, :name %>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me "Arbitrary Objects" or just "Objects" is the clearest.
The API docs doesn't use any adjective either:
https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's leave it as "Arbitrary Objects". Thank you, @p8! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
This fleshes out the "Choices from a Collection of Complex Objects" section a bit more, explicitly mentioning associations and proper field naming.
d2e56b0
to
a3a42f6
Compare
…icitly-mention-associations Mention associations in Form Helpers guide [ci-skip] (cherry picked from commit 66d8f8c)
This fleshes out the "Choices from a Collection of Complex Objects" section a bit more, explicitly mentioning associations and proper field naming.
/cc @ghiculescu Does this address your concern from #39344 (comment)?