Skip to content

[Documentation] Form: document Rails form_with integration and real-world examples#434

Merged
cirdes merged 2 commits into
mainfrom
docs/form-rails-integration
Jun 22, 2026
Merged

[Documentation] Form: document Rails form_with integration and real-world examples#434
cirdes merged 2 commits into
mainfrom
docs/form-rails-integration

Conversation

@djalmaaraujo

@djalmaaraujo djalmaaraujo commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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 / id to give each input so Rails params parse correctly
  • How to wire a CSRF token
  • How to map model.errors to FormFieldError

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:

  1. "Rails Integration" heading + prose — explains the recommended strategy: use form_with (or set action manually), set explicit name/id on every input, include the CSRF hidden field, and pass server-side errors via FormFieldError.
  2. "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.
  3. "Devise-style login form" code example — a complete sign-in form using session[email] / session[password] / session[remember_me] params, autocomplete attributes, minlength validation, and error display — the real-world pattern most Rails devs need.

Testing instructions

  • Visit /docs/form on 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_with for action + CSRF, setting explicit name/id, and showing server errors with FormFieldError + 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], with autocomplete, minlength, and error display.
  • Bug Fixes

    • Render the two Rails examples as syntax-highlighted code via Heading + Codeblock (no instance_eval) to avoid crashes from missing helpers.* routes in the docs app; rebuilt mcp/data/registry.json.

Written for commit 55fd108. Summary will update on new commits.

Review in cubic

…orld examples (#134)

Add a "Rails Integration" section to the Form docs covering:
- Prose intro explaining the recommended strategy (form_with, explicit name/id, CSRF, FormFieldError for server errors)
- Minimal single-field Rails form example with action, CSRF token, and FormFieldError
- Devise-style login form example (email, password, remember me) with proper session[...] params and error handling
@djalmaaraujo djalmaaraujo requested a review from cirdes as a code owner June 22, 2026 20:08

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

…egistry (#434)

Convert the two Rails-integration examples ("Minimal Rails form" and
"Devise-style login form") from VisualCodeExample to Heading + Codeblock
so they are displayed as syntax-highlighted code without being live-rendered
via instance_eval. This fixes the ComponentsControllerTest crash caused by
helpers.users_path and helpers.user_session_path not existing in the docs app.

Also rebuild mcp/data/registry.json to include the updated form docs.
@djalmaaraujo

Copy link
Copy Markdown
Contributor Author

CI fixes applied

Failure 1 — Docs test crash (NoMethodError: undefined method 'users_path')

The two Rails-integration examples ("Minimal Rails form" and "Devise-style login form") in both docs/app/views/docs/form.rb and gem/lib/ruby_ui/form/form_docs.rb were wrapped in Docs::VisualCodeExample, which calls @context.instance_eval(code) to live-render a preview. The code referenced helpers.users_path and helpers.user_session_path which don't exist in the docs app, causing the controller test to crash.

Fix: Replaced both VisualCodeExample blocks with Heading(level: 3) + Codeblock(<<~RUBY, syntax: :ruby) — the same pattern used in docs/app/views/docs/data_table.rb. The code is now displayed as syntax-highlighted text only, never executed.

Failure 2 — MCP registry out of date

Re-ran cd mcp && bundle exec exe/ruby-ui-mcp-build, committed the updated mcp/data/registry.json.

Verified locally:

  • gem: 225 tests, 992 assertions, 0 failures — StandardRB clean (366 files)
  • docs: 63 tests, 63 assertions, 0 failures, 0 errors — StandardRB clean
  • ruby -c on both changed view files: Syntax OK
  • git diff --exit-code mcp/data/registry.json: clean after commit

@cirdes cirdes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cirdes cirdes merged commit 2878c1f into main Jun 22, 2026
8 checks passed
@cirdes cirdes deleted the docs/form-rails-integration branch June 22, 2026 23:17
@djalmaaraujo djalmaaraujo mentioned this pull request Jun 23, 2026
djalmaaraujo added a commit that referenced this pull request Jun 23, 2026
- Bump RubyUI::VERSION to 1.4.0 and regenerate both lockfiles
- Update home hero badge to "Native Dialog, Form docs, and more"
  (header version badge reads RubyUI::VERSION, updates automatically)
- Rebuild MCP registry for 1.4.0

Highlights since v1.3.0: native <dialog> element (#435), accordion
closed-content visibility fix (#433), Form Rails-integration docs (#434),
multi-component generator and as:-render options.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form component needs more extensive documentation

2 participants