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

Prefer form builder methods in Form Helpers guide [ci skip] #39344

Merged
merged 1 commit into from
May 28, 2020

Conversation

jonathanhefner
Copy link
Member

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. 馃槄

@rails-bot rails-bot bot added the docs label May 19, 2020
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]`.
Copy link
Member

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.

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 think git's intra-line diff is actually pretty good for long lines (example, example), but I do agree we should try to minimize diffs. I changed this to only unwrap the lines that I completely rewrote.

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.
@jonathanhefner jonathanhefner merged commit 2d6a8d7 into rails:master May 28, 2020
<%= 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" %>
Copy link
Member

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
Copy link
Member

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.

@vipulnsward
Copy link
Member

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

jonathanhefner added a commit to jonathanhefner/rails that referenced this pull request Jun 4, 2020
Follow-up to rails#39344.

Adds back mention of `text_area` helper.
jonathanhefner added a commit to jonathanhefner/rails that referenced this pull request Jun 4, 2020
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.
Copy link
Member

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.

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

3 participants