Show story idea body as required and humanize its error#1561
Conversation
The story idea form's body field gave no visual cue it was required, and its validation error surfaced the internal "Rhino body" attribute name to public submitters. Mark the label required and relabel the attribute as "Body" so the error reads naturally. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
|
||
| label_tag = | ||
| if label.present? | ||
| label_content = required ? safe_join([ label, " ", content_tag(:abbr, "*", title: "required", class: "text-red-600 no-underline") ]) : label |
There was a problem hiding this comment.
Scoped the required marker behind a keyword (default false) so the ~40 other rhino_editor callers keep the optional styling unchanged.
| activerecord: | ||
| attributes: | ||
| story_idea: | ||
| rhino_body: "Body" |
There was a problem hiding this comment.
Overriding the attribute's human name here makes full_messages (used by the shared errors partial) read "Body can't be blank" instead of leaking the internal rhino_body name. Follows the existing workshop_variation pattern.
There was a problem hiding this comment.
Pull request overview
This PR improves the Story Idea submission UX by (1) visually indicating that the body field is required and (2) ensuring validation errors display a user-friendly attribute label (“Body”) instead of the internal “Rhino body”.
Changes:
- Added an optional
required:keyword to the sharedrhino_editorhelper to append a red*marker and apply arequiredlabel class. - Marked the Story Idea body editor as required in the Story Idea form partial.
- Added an I18n attribute translation for
story_idea.rhino_bodyand a request spec asserting the humanized error message.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| spec/requests/story_ideas_spec.rb | Adds a regression test ensuring the rendered validation error says “Body can’t be blank” and not “Rhino body”. |
| config/locales/en.yml | Adds an attribute translation so Rails full validation messages use “Body” for StoryIdea#rhino_body. |
| app/views/story_ideas/_form.html.erb | Marks the Story Idea body rhino_editor label as required to show a visual cue. |
| app/helpers/rhino_editor_helper.rb | Extends the shared rhino_editor helper with a required: option that adds a required marker and required/optional label class. |
| form.label( | ||
| base_attribute_name, | ||
| label, | ||
| class: "block font-medium mb-1 text-gray-700 text optional" | ||
| label_content, | ||
| class: "block font-medium mb-1 text-gray-700 text #{required ? "required" : "optional"}" | ||
| ) |
What is the goal of this PR and why is this important?
How did you approach the change?
required:keyword to therhino_editorhelper that switches the label to therequiredclass and appends a red*marker. Defaulted tofalseso the helper's other ~40 usages (workshops, events, etc.) are unaffected.required: trueto the body field on the story idea form.activerecord.attributes.story_idea.rhino_body: "Body"toen.yml(matching the existingworkshop_variationpattern) so the error reads "Body can't be blank".UI Testing Checklist
*required markerAnything else to add?
rhino_editorhelper change is scoped behind a parameter, so no other forms change behavior.