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

Mention associations in Form Helpers guide [ci-skip] #45779

Conversation

jonathanhefner
Copy link
Member

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)?

@rails-bot rails-bot bot added the docs label Aug 5, 2022
@@ -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
Copy link
Member

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:

Suggested change
Choices from a Collection of Complex Objects
Choices from a Collection of Model Objects

Copy link
Member Author

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.)

Copy link
Member

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:

Suggested change
Choices from a Collection of Complex Objects
Choices from a Collection of Objects

Copy link
Member Author

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?

Copy link
Member

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 %>

Copy link
Member

@p8 p8 Aug 12, 2022

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

Copy link
Member Author

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! 😄

Copy link
Member

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.
@jonathanhefner jonathanhefner force-pushed the guide-form_helpers-explicitly-mention-associations branch from d2e56b0 to a3a42f6 Compare August 12, 2022 20:41
@jonathanhefner jonathanhefner merged commit 66d8f8c into rails:main Aug 12, 2022
jonathanhefner added a commit that referenced this pull request Sep 30, 2022
…icitly-mention-associations

Mention associations in Form Helpers guide [ci-skip]

(cherry picked from commit 66d8f8c)
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