[Documentation] Form: document Rails form_with integration and real-world examples
Merged
DJ
5mo ago+179+179+012345678901234567890123456789-1-1-0123456789
Closes #134
How to reproduce the gap
Open https://rubyui.com/docs/form — the existing docs show visual examples (disabled, error states, checkbox, select, combobox) but give no guidance on:
- How to set the form
action/ HTTP method - What
name/idto give each input so Rails params parse correctly - How to wire a CSRF token
- How to map
model.errorstoFormFieldError
What changed
Three new items added immediately before the component-setup tabs in both gem/lib/ruby_ui/form/form_docs.rb and docs/app/views/docs/form.rb:
- "Rails Integration" heading + prose — explains the recommended strategy: use
form_with(or setactionmanually), set explicitname/idon every input, include the CSRF hidden field, and pass server-side errors viaFormFieldError. - "Minimal Rails form" code example — a single-field form with
action: helpers.users_path, CSRF token,FormFieldError, and a submit button; demonstrates the basic wiring. - "Devise-style login form" code example — a complete sign-in form using
session[email]/session[password]/session[remember_me]params,autocompleteattributes,minlengthvalidation, and error display — the real-world pattern most Rails devs need.
Testing instructions
- Visit
/docs/formon a local or preview build and confirm the three new items appear below the Combobox example - Verify the code blocks render correctly (no syntax highlighting errors)
- Copy the "Minimal Rails form" snippet into a Phlex view in a Rails app and confirm it submits with the correct params
- Copy the "Devise-style login form" snippet and confirm Devise recognises the
session[email]/session[password]parameters
Summary by cubic
Adds a “Rails Integration” section to the Form docs with clear guidance on form_with, CSRF, input name/id, and mapping server errors to FormFieldError. Converts the Rails examples to code-only blocks so they don’t execute Rails helpers in the docs app.
-
New Features
- Prose on using
form_withfor action + CSRF, setting explicitname/id, and showing server errors withFormFieldError+model.errors. - Minimal Rails form example with a single email field, hidden CSRF input, and a submit button.
- Devise-style login example using
session[email],session[password],session[remember_me], withautocomplete,minlength, and error display.
- Prose on using
-
Bug Fixes
- Render the two Rails examples as syntax-highlighted code via
Heading+Codeblock(noinstance_eval) to avoid crashes from missinghelpers.*routes in the docs app; rebuiltmcp/data/registry.json.
- Render the two Rails examples as syntax-highlighted code via