Rails forms: form_with
This course covers form_with, the Rails helper this project uses for forms bound to a model. It shows how form_with model: picks the HTTP method and button label for new and saved records. It explains how the form builder generates fields with inferred name, id and value. It traces a field named article[title] through the request body into params[:article][:title] and article_params. It follows the same chain through the project's identity settings form and explains the authenticity token that protects against CSRF.
What you'll learn
- ✓How form_with model: builds forms for new and saved records
- ✓How f.text_field and f.submit infer name, id, value and label from the model
- ✓How bracketed field names become nested params such as params[:article][:title]
- ✓How param_key connects the identity settings form to settings_params
- ✓What the authenticity token does against CSRF
From generated tags to a generated form
ActionController: actions showed a form's fields arriving as params[:article][:title] without showing what sent them. Controller params & security opened article_params, params.require(:article).permit(:title), without showing where the nested :article key comes from. Both pointed at the same gap:…
Read the full lesson free →Curriculum
7 lessonsFrom generated tags to a generated form
Introduces form_with as the helper that generates a form whose fields arrive as params[:article][:title].
form_with model: one helper for new and existing records
Shows form_with model: generating a form, and how a saved record adds a hidden _method patch field.
The form builder: f.text_field and f.submit
Explains how f.text_field infers name, id and value from the model, and how f.submit picks its label.
Where article[title] lands: params[:article][:title]
Traces the article[title] field name through the request body into params[:article][:title] and article_params.
The same chain, in this project's real settings form
Follows the same chain through this project's settings form, from the identity_user param_key to settings_params.
The hidden field every form_with already adds
Explains the hidden authenticity_token field that form_with adds by default and how it blocks CSRF forgeries.
Putting it together: form_with's full shape
Reviews each piece of form_with through one real form, from model binding to the CSRF token.