Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/helpers/rhino_editor_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module RhinoEditorHelper
# custom rhino editor with stimulus controller attached to edit raw source html
def rhino_editor(form, base_attribute_name, label: nil, hint: nil)
def rhino_editor(form, base_attribute_name, label: nil, hint: nil, required: false)
rhino_attr = :"rhino_#{base_attribute_name}"
field_id = form.field_id(rhino_attr)
value = form.object.public_send(rhino_attr)

label_tag =
if label.present?
label_content = required ? safe_join([ label, " ", content_tag(:abbr, "*", title: "required", class: "text-red-600 no-underline") ]) : label

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Scoped the required marker behind a keyword (default false) so the ~40 other rhino_editor callers keep the optional styling unchanged.

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"}"
)
Comment on lines 11 to 15
end

Expand Down
1 change: 1 addition & 0 deletions app/views/story_ideas/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<% else %>
<div class="form-group <%= 'has-error' if f.object.errors[:rhino_body].present? %>">
<%= rhino_editor(f, :body,
required: true,
label: "Please share details about your participant(s) (while maintaining confidentiality)
and their workshop goals, including what happened during the workshop, and how creating made an impact.
Include direct quotes whenever possible.",
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ en:
hello: "Hello world"
activerecord:
attributes:
story_idea:
rhino_body: "Body"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

workshop_variation:
rhino_body: "Details"
workshop_variation_idea:
Expand Down
6 changes: 6 additions & 0 deletions spec/requests/story_ideas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@
post story_ideas_url, params: { story_idea: invalid_attributes }
expect(response).to have_http_status(:unprocessable_content)
end

it "labels the body error as 'Body', not 'Rhino body'" do
post story_ideas_url, params: { story_idea: invalid_attributes }
expect(response.body).to include("Body can&#39;t be blank")
expect(response.body).not_to include("Rhino body")
end
end

describe "PATCH /update" do
Expand Down
Loading