-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Prefer form builder methods in Form Helpers guide [ci skip] #39344
Prefer form builder methods in Form Helpers guide [ci skip] #39344
Conversation
guides/source/form_helpers.md
Outdated
value entered by the user for that field. For example, if the form contains | ||
`<%= text_field_tag(:query) %>`, then you would be able to get the value of this | ||
field in the controller with `params[:query]`. | ||
The form builder object yielded by `form_with` provides numerous helper methods for generating form elements such as text fields, checkboxes, and radio buttons. The first parameter to these methods is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the `params` in the controller with the value entered by the user for that field. For example, if the form contains `<%= form.text_field :query %>`, then you would be able to get the value of this field in the controller with `params[:query]`. |
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.
Let's retain the multi-line if possible(unless this was visually affecting something).
It's easier to read/change in future than a single line + better for diffs.
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.
edb1461
to
c0c6d1d
Compare
The Form Helpers guide should encourage users to use `form_with` and associated builder methods. The lower-level `*_tag` methods are covered by the API docs. These changes also fix some discrepancies between code examples and their descriptions.
c0c6d1d
to
612eb35
Compare
<%= time_field(:task, :started_at) %> | ||
<%= number_field(:product, :price, in: 1.0..20.0, step: 0.5) %> | ||
<%= range_field(:product, :discount, in: 1..100) %> | ||
<%= form.hidden_field :parent_id, value: "foo" %> |
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 forgot to post review comments. This one is missing one tag.
|
||
WARNING: When `:include_blank` or `:prompt` are not present, `:include_blank` is forced true if the select attribute `required` is true, display `size` is one, and `multiple` is not true. | ||
|
||
### Option Tags from a Collection of Arbitrary 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.
Don't think we should remove this, there is no easy way to get to these. I have ended up on these docs quite a lot.
@jonathanhefner Although we migrated to form model usage, I don't think the guide warrants to remove all tag related docs that are not support by form_with, we should partially revert this. |
Follow-up to rails#39344. Adds back mention of `text_area` helper.
Follow-up to rails#39344. This adds back coverage of `collection_select`, adds new coverage of `collection_radio_buttons`, revises existing coverage of `collection_check_boxes`, and unifies these sections.
<% end %> | ||
``` | ||
|
||
WARNING: If you are using `select` or similar helpers to set a `belongs_to` association you must pass the name of the foreign key (in the example above `city_id`), not the name of association itself. |
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 think this was worth retaining - the new docs don't talk about associations at all, which is a common use case for f.select
.
The Form Helpers guide should encourage users to use
form_with
and associated builder methods. The lower-level*_tag
methods are covered by the API docs.These changes also fix some discrepancies between code examples and their descriptions.
There are still several sections here that could use improvement. But this diff is already much longer than I'd hoped, and this felt like an OK checkpoint for this rabbit hole. 馃槄